#include <bits/stdc++.h>
using namespace std;
int q = 1;
void solve() {
  int hh, mm;
  cin >> hh >> mm;
  int ans = (23 - hh) * 60;
  ans += (60 - mm);
  cout << ans << endl;
}
int main() {
  std::ios_base::sync_with_stdio(false);
  cin >> q;
  while (q--) {
    solve();
  }
}
