#include using namespace std; int cas,a,b,dp[1005][1005]; int main() { for (int i=1;i<=1000;++i) for (int j=1;j<=1000;++j) dp[i][j]=max(dp[i-1][j],dp[i][j-1])+(__gcd(i,j)==1); scanf("%d",&cas); while (cas--) { scanf("%d%d",&a,&b); printf("%d\n",dp[a][b]); } return 0; }