#include using namespace std; typedef signed long long ll; #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define FORR2(x,y,arr) for(auto& [x,y]:arr) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) template bool chmax(T &a, const T &b) { if(a bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;} //------------------------------------------------------- ll A,B,C,D; void solve() { int i,j,k,l,r,x,y; string s; cin>>A>>B>>C>>D; if(A==C&&B==D) { cout<<0<> V,W; while(abs(A)&&abs(B)) { if(abs(A)>abs(B)) { V.push_back({1,A/B}); A-=A/B*B; } else { V.push_back({2,B/A}); B-=B/A*A; } } if(A==0) { if(B>0) { V.push_back({1,1}); V.push_back({2,-1}); } else { V.push_back({1,-1}); V.push_back({2,1}); } } else if(A<0) { V.push_back({2,-1}); V.push_back({1,2}); V.push_back({2,-1}); } while(abs(C)&&abs(D)) { if(abs(C)>abs(D)) { W.push_back({2,C/D}); C-=C/D*D; } else { W.push_back({1,D/C}); D-=D/C*C; } } if(C==0) { if(D>0) { W.push_back({2,1}); W.push_back({1,-1}); } else { W.push_back({2,-1}); W.push_back({1,1}); } } else if(C<0) { W.push_back({1,-1}); W.push_back({2,2}); W.push_back({1,-1}); } while(W.size()) V.push_back(W.back()),W.pop_back(); cout<