#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int h, m, c;
    cin >> h >> m;
    c = (1440 - ((h * 60) + m));
    cout << c << endl;
  }
  return 0;
}
