Can someone tell me why this solution is not getting accepted for 'SNAKPROC

#include <iostream>
#include <queue>
using namespace std;

void solve(){
    
    queue<char> q;
    
    int n;
    cin>>n;
    string arr;
    cin>>arr;
    
    for(auto x:arr)
        {
            if(x == 'H' || x == 'T')
                q.push(x);
        }
        
        char x;
    
    if(q.size()%2!=0){
        
            cout<<"Invalid\n";
            return;
    }    
        
    while(q.size() > 0){
        
        x = q.front();
        
        q.pop();
        
        if(q.front()==x){
            cout<<"Invalid\n";
            return;}
        
        
    }
    
    cout<<"Valid\n";
}

int main() {

    int t;
    cin>>t;
    
    while(t--){
        
        solve();
    }
	return 0;
}

Reading from any empty queue on the sample test input:

[simon@simon-laptop][10:59:30]
[~/devel/hackerrank/otherpeoples]>./compile-latest-cpp.sh 
Compiling giantkiller18-SNAKPROC.cpp
+ g++ -std=c++17 giantkiller18-SNAKPROC.cpp -O3 -g3 -Wall -Wextra -Wconversion -DONLINE_JUDGE -D_GLIBCXX_DEBUG -fsanitize=undefined -ftrapv
+ set +x
Successful
[simon@simon-laptop][10:59:45]
[~/devel/hackerrank/otherpeoples]>echo "6
18
..H..T...HTH....T.
3
...
10
H..H..T..T
2
HT
11
.T...H..H.T
7
H..T..H" | ./a.out
/usr/include/c++/7/bits/stl_queue.h:204: std::queue<_Tp, _Sequence>::reference std::queue<_Tp, _Sequence>::front() [with _Tp = char; _Sequence = std::__debug::deque<char, std::allocator<char> >; std::queue<_Tp, _Sequence>::reference = char&]: Assertion '__builtin_expect(!this->empty(), true)' failed.
Aborted (core dumped)

Edit:

And when you’ve fixed that: consider the test input:

1                                                       
2
TH