#include <iostream>
using namespace std;
typedef unsigned long ulong;
namespace Math {
void Euclid_it(ulong a, ulong b, ulong *p) {
ulong r;
while(b){
r = a % b;
a = b;
b = r;
}
*p = a;
}
ulong Euclid_rec(ulong a, ulong b, ulong *p) {
if( b == 0 ) {
*p = a;
} else return Euclid_rec(b, a % b, p);
}
};
int main(int argc, char const *argv[])
{
int nPairs;
ulong first,
second,
result;
cin>>nPairs;
for(int i = 0; i < nPairs; ++i) {
cin>>first>>second;
Math::Euclid_it(first, second, &result);
cout<<result<<"\n";
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKIAp0eXBlZGVmIHVuc2lnbmVkIGxvbmcgdWxvbmc7CiAKbmFtZXNwYWNlIE1hdGggewogICAgICAgICAKICAgICAgICAgIHZvaWQgRXVjbGlkX2l0KHVsb25nIGEsIHVsb25nIGIsIHVsb25nICpwKSB7CiAKICAgICAgICAgICAgICB1bG9uZyByOwogCiAgICAgICAgICAgICAgd2hpbGUoYil7CiAgICAgICAgICAgICAgCXIgPSBhICUgYjsKICAgICAgICAgICAgICAJYSA9IGI7CiAgICAgICAgICAgICAgCWIgPSByOwogICAgICAgICAgICAgIH0KIAogICAgICAgICAgICAgICpwID0gYTsKICAgICAgICAgIH0KIAogICAgICAgICAgdWxvbmcgRXVjbGlkX3JlYyh1bG9uZyBhLCB1bG9uZyBiLCB1bG9uZyAqcCkgewogCiAgICAgICAgICAgICAgaWYoIGIgPT0gMCApICB7CiAKICAgICAgICAgICAgICAJICAqcCA9IGE7CiAKICAgICAgICAgICAgICB9IGVsc2UgcmV0dXJuIEV1Y2xpZF9yZWMoYiwgYSAlIGIsIHApOwogICAgICAgICAgfQogCn07CiAKaW50IG1haW4oaW50IGFyZ2MsIGNoYXIgY29uc3QgKmFyZ3ZbXSkKewkKCQoJaW50IG5QYWlyczsKCXVsb25nIGZpcnN0LCAKCSAgICAgIHNlY29uZCwgCgkgICAgICByZXN1bHQ7CiAKCWNpbj4+blBhaXJzOwogCglmb3IoaW50IGkgPSAwOyBpIDwgblBhaXJzOyArK2kpIHsKIAoJCWNpbj4+Zmlyc3Q+PnNlY29uZDsKIAoJCU1hdGg6OkV1Y2xpZF9pdChmaXJzdCwgc2Vjb25kLCAmcmVzdWx0KTsKIAoJCWNvdXQ8PHJlc3VsdDw8IlxuIjsKCX0KIAogCgkKCXJldHVybiAwOwp9