programming languages – doubts on cin and scanf


i spent literally 5hrs trying to figure out, why the value of n is 1 for my second test case ( which begins at line 12 ) , but i am unable to, could you help me with that?

    int t,n,i,j;
    char c;
    cin>>t;
    while(t--)
    {
        cin>>n;
        cout<<n<<"n";
        getchar();
        while(scanf("%c %d %dn",&c,&i,&j)==3)
        {
            cout<<c<<" "<<i<<" "<<j<<"n";
        }
        getchar();
    }

test case:-
first line represents the number of test cases, and each test case has a blank line.

2

10
c 1 5
c 2 7
q 7 1
c 3 9
q 9 6
c 2 5
q 7 5

2
q 1 1
c 1 1
q 1 1

output :-

10
c 1 5
c 2 7
q 7 1
c 3 9
q 9 6
c 2 5
q 7 5
1

```