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