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