#include <bits/stdc++.h>
using namespace std;
int h, m;
void read() { cin >> h >> m; }
void solve() { cout << 24 * 60 - 60 * h - m << "\n"; }
int main() {
  ios ::sync_with_stdio(false);
  cin.tie(nullptr);
  int t = 1;
  cin >> t;
  while (t) {
    --t;
    read();
    solve();
  }
  return 0;
}
