#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int h, m, ans = 0;
    cin >> h >> m;
    int diffh = 24 - h;
    int diffm = 60 - m;
    ans = (diffh - 1) * 60 + diffm;
    cout << ans << "\n";
  }
  return 0;
}
