#include #include #include #include #include using namespace std; int gcd(int a,int b){ int ans; if(!b){ return 0; } ans = a/b; ans += gcd(b,a%b); return ans; } int main() { int n,m,T; ///freopen("in.txt","r",stdin); scanf("%d",&T); while(T--){ scanf("%d%d",&n,&m); printf("%d\n",gcd(n,m)); } return 0; }