#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, m;
  int n, a[2000];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> h >> m;
    a[i] = ((24 - h) * 60) - (m);
  }
  for (int i = 0; i < n; i++) {
    cout << a[i] << endl;
  }
}
