#include <bits/stdc++.h>
#define ll long long
#define YES cout << "YES\n";
#define NO cout << "NO\n";
#define opps cout<<-1<<endl;
const ll con = 1e10 + 5;
using namespace std;
void solve() {
    int n  , x = 0  ;
    cin >> n ;
    cin.ignore();
    vector<string> a;
    while (n--){
        string s;
        getline(cin, s);
        if (s == "LEFT") {
            x--;
            a.push_back("LEFT");
        }
        else if (s == "RIGHT") {
            x++;
            a.push_back("RIGHT");
        }
        else {
            string tr = s.substr(8);
            int j = stoi(tr);
            string we = a[j - 1];
            (we == "LEFT") ? x-- : x++;
            a.push_back(we);
        }
    }
    cout << x << endl;
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    cin>>t;
    while(t--)
        solve();
}