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