#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int h, m, res;
    cin >> h >> m;
    if (h == 23) {
      res = 60 - m;
    }
    if (h < 23) {
      res = (23 - h) * 60 + 60 - m;
    }
    cout << res << endl;
  }
  return 0;
}
