#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int h, m, count = 0;
    cin >> h >> m;
    while (m != 60) {
      count++;
      m++;
    }
    h += 1;
    while (h != 24) {
      count += 60;
      h++;
    }
    cout << count << endl;
  }
}
