import java.util.*; import java.io.*; import java.text.*; //Solution Credits: Taranpreet Singh public class Main{ //SOLUTION BEGIN void pre() throws Exception{} void solve(int TC) throws Exception{ long n = nl(), ty = ni(), x = ni(), y = ni(), z = ni(); long N = 2*n+1; if(x==y || y==z)throw new Exception("Hold right there, Sparky!"); if(ty==3){ long t = x;x=z;z=t;ty = 1; } if(ty==4)ty = 2; if(y==0)print(1, N); else if(ty==1){ if(x