#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using pii = pair<int, int>;
const int MOD = 1e9 + 7;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t, h, ans, m;
  cin >> t;
  while (t--) {
    cin >> h >> m;
    h = abs(23 - h);
    m = abs(60 - m);
    ans = h * 60 + m;
    cout << ans << "\n";
  }
}
