#include #define rep(i,n) for (int i=0; i < (int)(n); i++) #define all(c) c.begin(), c.end() using namespace std; typedef long long ll; typedef long double ld; using vi = vector; using vvi = vector; using vl = vector; using vvl = vector; using P = pair; ll solve() { //答えはmax120程度 //BFS書けないか? ll sx,sy,tx,ty; cin>>sx>>sy>>tx>>ty; if(sy > 60 || ty > 60) return abs(sy - ty); //y>60なら左端マスがxの全範囲をカバー //x座標は左端に寄せる { ll dx = 1LL << sy; ll rem = sx % dx; sx -= rem; } { ll dx = 1LL << ty; ll rem = tx % dx; tx -= rem; } map dist; dist[P(sx,sy)] = 0; queue

Q; Q.emplace(sx,sy); while(!Q.empty()) { auto[x,y] = Q.front(); Q.pop(); P pos = P(x,y); if(x == tx && y == ty) return dist[pos]; ll dx = 1LL << y; if(x < tx) { P nxt = P(x+dx, y); if(dist.count(nxt)) continue; dist[nxt] = dist[pos] + 1; Q.push(nxt); } if(tx < x) { P nxt = P(x-dx, y); if(dist.count(nxt)) continue; dist[nxt] = dist[pos] + 1; Q.push(nxt); } if(y < ty) { P nxt = P(x, y+1); if(dist.count(nxt)) continue; dist[nxt] = dist[pos] + 1; Q.push(nxt); } if(ty < y) { P nxt = P(x, y-1); if(dist.count(nxt)) continue; dist[nxt] = dist[pos] + 1; Q.push(nxt); } } return 0; } int main() { ios::sync_with_stdio(0); cin.tie(0); //入出力高速化 int T; cin>>T; rep(i,T) cout<