#include <bits/stdc++.h>
using namespace std;
bool sortbysec(const pair<long long, long long> &a,
               const pair<long long, long long> &b) {
  return (a.second < b.second);
}
int main() {
  long long t, h, m, n, l;
  cin >> t;
  n = 24 * 60;
  while (t--) {
    cin >> h >> m;
    l = (60 * h) + m;
    l = n - l;
    cout << l << endl;
  }
  return 0;
}
