/** * author: tourist * created: 03.06.2018 17:59:34 **/ #include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int tt; cin >> tt; while (tt--) { int h1, m1, h2, m2, k; cin >> h1 >> m1 >> h2 >> m2 >> k; int t1 = h1 * 60 + m1; int t2 = h2 * 60 + m2; int d = t1 + k * 60 - t2; cout << abs(d) << '\n'; } return 0; }