#include <bits/stdc++.h>
using namespace std;
const long long maxn = 2e5;
const long long OO = 1e18;
const long long mod = 1e9 + 7;
const double PI = acos(-1);
void maxself(long long &a, long long b) { a = max(a, b); }
void minself(long long &a, long long b) { a = min(a, b); }
int32_t main() {
  long long t;
  cin >> t;
  while (t--) {
    long long h, m;
    cin >> h >> m;
    long long sum = h * 60 + m;
    cout << 24 * 60 - sum << "\n";
  }
  return 0;
}
