#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int quer;
  cin >> quer;
  for (int qe = 0; qe < quer; ++qe) {
    int a, b;
    cin >> a >> b;
    int res = (24 - a - 1) * 60 + 60 - b;
    cout << res << "\n";
  }
  return 0;
}
