text: //Data Structure includes
  #include<vector>
  #include<stack>
  #include<set>
  #include<map>
  #include<queue>
  #include<deque>
  #include<string>
  //Other Includes
  #include<iostream>
  #include<algorithm>
  #include<cstring>
  #include<cassert>
  #include<cstdlib>
  #include<cstdio>
  #include<cmath>
  //some common functionn
  #define maX(a,b)                     ( (a) > (b) ? (a) : (b))
  #define miN(a,b)                     ( (a) < (b) ? (a) : (b))
  #define FOR(i,a,b)              for(int i=a;i<b;i++)
  #define FORs(i,a,b)             for(int i=a;i>=b;i--)
  #define fill(a,v)               memset(a,v,sizeof a)
  #define abS(x)                  ((x)<0?-(x):(x))
  #define mP                      make_pair
  #define pB                      push_back
  #define error(x)                cout << #x << " : " << (x) << endl
  // Input macros
  #define s(n)                        scanf("%d",&n)
  #define sc(n)                       scanf("%c",&n)
  #define sl(n)                       scanf("%lld",&n)
  #define sf(n)                       scanf("%lf",&n)
  #define ss(n)                       scanf("%s",n)
  
  // Output macros
  #define p(n)                        printf("%d",n)
  #define pc(n)                       printf("%c",n)
  #define pl(n)                       printf("%lld",n)
  #define pf(n)                       printf("%lf",n)
  #define ps(n)                       printf("%s",n)
  
  using namespace std;
  
  typedef long long LL;
  typedef pair<int,int> PII;
  typedef pair<LL,LL> PLL;
  typedef pair<int,PII> TRI;
  typedef vector<int> VI;
  typedef vector<LL> VL;
  typedef vector<PII> VII;
  typedef vector<PLL> VLL;
  typedef vector<TRI> VT;
  typedef vector<VI> VVI;
  typedef vector<VL> VVL;
  typedef vector<VII> VVII;
  typedef vector<VLL> VVLL;
  typedef vector<VT> VVT;
  
  using namespace std;
  /*  The Doer's code  */
  /*   INPUT
  
  
  1000000009 , 100005
  */
  
  //char name[103][25];
  
   set<string> myset;
    set<string>::iterator it,pt;
  string name[103],vote[103];
  
  int n,m;
  int solve()
  {
  	string mins="-";
  	int marks=0;
  	it=myset.end();
  	FORs(i,n-1,0)
  	{
  		it=myset.end();
  		int jam=0;
  		pt=myset.find(name[i]);
  		
  	    if(pt==it)
  		{
  
  			//cout<<vote[i];
  			if(vote[i]==mins)
  		    	marks--;//,cout<<name[i]<<jam;
  			else
  			   marks++;
  			myset.insert(name[i]);
  		}
  	}
  	cout<<marks<<endl;
  	myset.clear();
   	return 1;
  }
  
  bool input()
  {
  	 s(n);
  	 //gets(ch);
  	 FOR(i,0,n)
  	 {
  	 //	getline(cin,name[i]);
  		cin>>name[i];
  		cin>>vote[i];
  	    //myset.insert(name[i]);
  
  	 }
      return true;
  }
  
  int main()
  {
      int T=1;
      s(T);
      for(int testnum=1;testnum<=T;testnum++)
      {
          if(!input()) break;
  
          solve();
          //printf("\n");
  
      }
      return 0;
  }
  
  
  