#include <bits/stdc++.h>
using namespace std;
bool besarDulu(const int &a, const int &b) { return a > b; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int h, m;
    cin >> h >> m;
    int minutes = (24 - h - 1) * 60 + (60 - m);
    cout << minutes << '\n';
  }
  return 0;
}
