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