#include int josephus(int n, int m) { m++; if(n == 1) { return 0; } else { return (josephus(n-1, m) + m) % n; } } int main() { int n, m; scanf("%d",&m); while (m--) { scanf("%d", &n); int result = josephus(n, 0); printf("%d\n", result+1); } return 0; }