#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;
using LL = long long;

void solve()
{
    int n;
    if(!(cin >> n)) return;
    vector<LL> a(n+1);
    for(int i = 1;i <= n;i++)    cin >> a[i];
    
    string S;
    cin >> S;
    
    int ans{};
    for(int i = 1;i <= n;i++)
    {
        char op = S[i-1];
        if((op == '<') && (a[i] >= 0)) a[i] = -1 , ans++;
        else if((op == '>') && (a[i] <= 0)) a[i] = 1 , ans++;
        else if(op == 'Z')
        {
            //防止相乘结果过大
            bool condition = false;
            if(a[i] == 0 || a[i-1] == 0) condition = true;
            else if((a[i] > 0) != (a[i-1] > 0))//判断异号 
                condition = true;
            if(condition)
            {
                if(a[i-1] < 0) a[i] = -1;
                else if(a[i-1] > 0) a[i] = 1;
                ans++;
            }
        }
    }
    
    cout << ans << "\n";
    
    
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T;
    
    if(cin >> T)
    {
        while(T--)
        {
            solve();
        }
    }
        
    return 0;
}