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