Roadies and the Eliminations

All submissions for this problem are available.
Everyone knows about the Roadies event in VESIT. In some year, many students participated in this event and thus eliminations became a headache for the event organisers. Each student were numbered from 1 to N. To make the eliminations, they decided to eliminate the students on the following rule :
Start from student 1
Step 1 : Eliminate one student.
Step 2 : Keep one student.
Step 3 : Repeat Step 1 and 2 until one student is left.
For example, Number of students = 7
1 2 3 4 5 6 7
Student 1 is eliminated. student 2 is kept. student 3 is eliminated. student 4 is kept. student 5 is eliminated. student 6 is kept. student 7 is eliminated.
2 4 6
Now, from the list of kept students, Because the last Student 7 was eliminated, the next student will be kept. Therefore, Student 2 is kept. Student 4 is eliminated. Student 6 is kept.
2 6
Again, from the list of kept students, Because the last Student 6 was kept, the next student will be eliminated. Therefore, student 2 is eliminated. student 6 is kept. Now, Only one student is left. Hence, only student 6 wins the roadies.
You are a smart roadie and good programmer too. You want to win the Roadies event, so that you can earn a certificate. What should be your student number, so that you will win the event? Print this number.
Input
First line consists of T  denoting the number of testcases.
Then T lines will consist of only 1 integer N  denoting the number of students participating in the event.
 If you have multiple test cases in a file start this section as: "The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows."
 Don't write any constraints here, use section "Constraints" for this below.
 If for example the input of each test is an array you could write it like this: "The first line of each test case contains a single integer N denoting the number of .... The second line contains N spaceseparated integers A_{1}, A_{2}, ..., A_{N} denoting the ...".
 If you have multiple test cases in a file start this section as: "The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows."
 Don't write any constraints here, use section "Constraints" for this below.
 If for example the input of each test is an array you could write it like this: "The first line of each test case contains a single integer N denoting the number of .... The second line contains N spaceseparated integers A_{1}, A_{2}, ..., A_{N} denoting the ...".
Output
For each testcase, output a single number you should have, so that you will win the event.
Tips: If you have multiple test cases in a file start this section as: "For each test case, output a single line containing...".
 If you have multiple test cases in a file start this section as: "For each test case, output a single line containing...".
Constraints
 1 ≤ T ≤ 100
 1 ≤ N ≤ 10^{6}
Example
Input: 3 7 5 10 Output: 6 2 4
Explanation
Example case 1. Already explained in problem statement.
Author:  shyamsingh8 
Tags  shyamsingh8 
Date Added:  6032016 
Time Limit:  1 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, PYP3, CLOJ, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 