#include <bits/stdc++.h>
using namespace std;
vector<long long> graph[101];
int level[101];
bool vis[101];
vector<vector<vector<long long>>> dp;
vector<vector<long long>> a;
long long hanoi(int n, int start, int end, int via) {
  if (n == 0) {
    return 0;
  }
  if (dp[n][start][end] != -1) return dp[n][start][end];
  dp[n][start][end] =
      min(a[start][end] + hanoi(n - 1, start, via, end) +
              hanoi(n - 1, via, end, start),
          a[start][via] + hanoi(n - 1, start, end, via) + a[via][end] +
              hanoi(n - 1, end, start, via) + hanoi(n - 1, start, end, via));
  return dp[n][start][end];
}
int main() {
  int t = 1;
  cin >> t;
  while (t--) {
    int h, m;
    cin >> h >> m;
    int ans = 24 - h - 1;
    if (m == 0) ++ans;
    ans *= 60;
    if (m != 0) ans += 60 - m;
    cout << ans << endl;
  }
  return 0;
}
