#include <bits/stdc++.h>
using namespace std;
using ld = long double;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
const int MX = 1e5;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int hh;
    cin >> hh;
    int mm;
    cin >> mm;
    int res = 0;
    if (mm != 0) {
      res += 60 - mm;
      mm = 0;
      hh++;
      if (hh == 24) hh = 0;
    }
    if (hh != 0) {
      res += (24 - hh) * 60;
    }
    cout << res << '\n';
  }
  return 0;
}
