#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int n2;
  int h, m;
  cin >> n2;
  while (cin >> h >> m) {
    cout << 60 * (23 - h) + (60 - m) << endl;
  }
  return 0;
}
