#include <bits/stdc++.h>
using namespace std;
vector<int> v;
int main() {
  int mm, hh, t;
  cin >> t;
  for (int i = 1; i <= t; i++) {
    cin >> hh >> mm;
    v.push_back((60 - mm) + (23 - hh) * 60);
  }
  for (int j = 0; j < t; j++) cout << v[j] << endl;
}
