#include <stdio.h>#include <algorithm>using namespace std;int f[30];int myabs(int a){ return a > 0 ? a : (-a);}int cal(int a, int b, int c){ f[0] = a; f[1] = b; f[2] = c; f[3] = a + b; f[4] = a + c; f[5] = b + c; f[6] = myabs(a - b); f[7] = myabs(a - c); f[8] = myabs(b - c); f[9] = a + b + c; f[10] = myabs(a + b - c); f[11] = myabs(a + c - b); f[12] = myabs(b + c - a); sort(f, f + 13); int s = 1, k = 0; while(f[k] == 0) { k++; } for(int i = k + 1; i <= 12; i++) { if(f[i] != f[i - 1] ) { s++; } } return s;}int main(){ int t, x, y, ans, s; scanf("%d", &t); while(t--) { ans = 0; scanf("%d%d", &x, &y); for(int i = 1; i <= x / 2; i++) { s = cal(i, x - i, y); if(s > ans) { ans = s; } } for(int i = 1; i <= y / 2; i++) { s = cal(i, y - i, x); if(ans < s) { ans = s; } } printf("%dn", ans); } return 0;}


