#include #include #include #include using namespace std; int f[1010][1010]; int _max(int x, int y) { return x > y ? x : y; } int gcd(int a, int b) { return a == 0 ? b : gcd(b%a, a); } int main() { int i, j, k; int T; scanf("%d", &T); f[1][1] = 1; for(i = 1; i <= 1000; i++){ for(j = 1; j <= 1000; j++){ if(i == 1 && j == 1) continue; if(i > 1) f[i][j] = _max(f[i][j], f[i-1][j]); if(j > 1) f[i][j] = _max(f[i][j], f[i][j-1]); if(gcd(i, j) == 1) f[i][j]++; } } while(T--){ int x, y; scanf("%d%d", &x, &y); printf("%d\n", f[x][y]); } return 0; }