#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int h, m;
    cin >> h >> m;
    int sol = 0;
    int aux = 23 - h;
    aux *= 60;
    sol += aux;
    sol += 60 - m;
    cout << sol << "\n";
  }
  return 0;
}
