#include <iostream> using namespace std; int main() { int a, b, c, d; cin >> a; d = 0; for (int i = 0; i < a; i++) { cin >> b >> c; d = 1440 - (b * 60) - c; cout << d << endl; } }