#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int i, t;
  cin >> t;
  while (t--) {
    int n, m;
    int H = 0;
    int M = 0;
    cin >> n >> m;
    M = (60 - m);
    H = (24 - (n + 1)) * 60;
    cout << H + M << endl;
  }
}
