#include #define rep(i,n) for (int i=0; i<(int)(n); i++) #define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++) using namespace std; using ll = long long; using P = pair; bool dfs(int n, vector> &visited, int gx, int gy, int &t, int x=0, int y=0, int d=0) { if (gx == x && gy == y) return true; rep(i, 4) { int nd = d % 4; int nx=x, ny=y; if (nd == 0) ny++; else if (nd == 1) nx++; else if (nd == 2) ny--; else if (nd == 3) nx--; if (0 <= nx && nx < n && 0 <= ny && ny < n) { if (visited[nx][ny] == -1) { visited[nx][ny] = 1; if (dfs(n, visited, gx, gy, ++t, nx, ny, d)) return true; else return false; } } d++; } return false; } int main() { int q; cin >> q; rep(i,q) { int n, x, y, t=0; cin >> n >> x >> y; vector> visited(n,vector (n, -1)); visited[0][0] = 1; dfs(n,visited, x, y, t); cout << t << endl; } }