#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int a, b, s;
    cin >> a >> b;
    s = a * 60 + b;
    cout << (1440 - s) << endl;
  }
  return 0;
}
