#include<iostream>
#define ll long long
#include<vector>
#include<stack>
#include<string>
#include<algorithm>
using namespace std;
void solve()
{
ll n;
cin >> n;
string ans;
cin >> ans;
stack<char> s;
for (ll i = 0; i < n; i++)
{
if (ans[i] >= 65 && ans[i] <= 90)
{
if (s.empty())
{
s.push(ans[i]);
}
else
{
if (s.top() == 'H' && ans[i] == 'T')
{
s.pop();
}
else
{
break;
}
}
}
}
if (s.empty())
{
cout << "Valid
";
}
else
{
cout << "Invalid
";
}
}
int main()
{
int t;
cin >> t;
while (t--)
{
solve();
}
return 0;
}