#include <bits/stdc++.h>

using namespace std;

// thank you geothermal :goat:
void __deb(int t) {cerr << t;}
void __deb(long t) {cerr << t;}
void __deb(long long t) {cerr << t;}
void __deb(unsigned int t) {cerr << t;}
void __deb(unsigned long t) {cerr << t;}
void __deb(unsigned long long t) {cerr << t;}
void __deb(float t) {cerr << t;}
void __deb(double t) {cerr << t;}
void __deb(long double t) {cerr << t;}
void __deb(char t) {cerr << '\'' << t << '\'';}
void __deb(const char *t) {cerr << '\"' << t << '\"';}
void __deb(const string &t) {cerr << '\"' << t << '\"';}
void __deb(bool t) {cerr << (t ? "true" : "false");}
template<typename T, typename V>
void __deb(const pair<T, V> &x){ cerr << '{'; __deb(x.first); cerr << ", "; __deb(x.second); cerr << '}'; }
template<typename T>
void __deb(const T &x){
    int f = 0; cerr << '{'; 
    for(auto &i: x){ if(f++) cerr << ", "; __deb(i);}
    cerr << "}";
}
void _rdeb(vector<string> &names, int ind){}
template<typename T, typename... V>
void _rdeb(vector<string> &names, int ind, T t, V... v){
    if(ind != 0) cerr << "==============\n";
    cerr << names[ind] << '\n'; __deb(t); cerr << '\n';
    _rdeb(names, ind+1, v...);
}
template<typename... V>
void _deb(string vars, V... v){
    vector<string> names(1); int in{};
    for(char c : vars)
        if(c == ',' && in == 0){
            while(names.back().size() && isspace(names.back().back())) names.back().pop_back();
            names.push_back("");
        }else{
            if(c == '(') in++; if(c == ')') in--;
            if(!isspace(c) || names.back().size()) names.back().push_back(c);
        }
    while(names.back().size() && isspace(names.back().back())) names.back().pop_back();
    _rdeb(names, 0, v...);
}
#ifdef DEBUG
#define deb(x...) {                              \
    cerr << __func__ << ':' << __LINE__ << '\n'; \
    _deb(#x, x);                                 \
    cerr << '\n';                                \
}
#define debsep(x...) {                           \
    cerr << __func__ << ':' << __LINE__ << '\n'; \
    _deb(#x, x);                                 \
    cerr << "****************************\n";    \
}
#else
#define deb(x...)
#define debsep(x...)
#endif

#define ar array
#define ll long long
typedef int uci;
#define int long long
#define F first
#define S second
typedef complex<double> cd;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define irep(i, a, b) for(int i = a; i > (b); --i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef pair<int, int> pii;
#define ve vector
typedef ve<int> vi;
typedef ve<vi> vvi;

struct debugger{
    template <typename T>
    debugger& operator<<(T &a){
        #ifdef DEBUG
            cerr << a;
        #endif
        return *this;
    }
    template <typename T>
    debugger& operator<<(T &&a){
        #ifdef DEBUG
            cerr << a;
        #endif
        return *this;
    }
} deb;

const double PI = acos(-1.0);
const int MAX_N = 1e5 + 1;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll LINF = 1e18;

template<typename T>
class sparseTable{
public:
    vector<int> powt;
    vector<vector<T>> stable;
    sparseTable(vector<T>& arr){
        int n = arr.size();
        powt.resize(n+1);
        for(int i{2}; i <= n; ++i){
            powt[i] = powt[i/2]+1;
        }

        stable = vector<vector<T>>(powt[n]+1, vector<T>(n));
        stable[0] = arr;
        for(int i{1}; i <= powt[n]; ++i){
            for(int j{}; j + (1ll<<i) <= n; ++j){
                stable[i][j] = sparseFunc(stable[i-1][j], stable[i-1][j+(1ll<<(i-1))]);
            }
        }
    };

    // [l, r], 0-indexed, range query
    T query(int l, int r){
        if(l > r || l < 0 || r >= stable[0].size()){
            return 3ll*LINF;
        }

        int pt = powt[r-l+1];
        return sparseFunc(stable[pt][l], stable[pt][r-(1ll<<pt)+1]);
    }

    inline T sparseFunc(const T& a, const T& b){
        return min(a, b);
    }
};
//! function insert

//THINK FIRST, CODE SECOND
//DON'T GET STUCK ON ONE STRATEGY
//CALM DOWNNN FOR ONCE IN YOUR LIFE
//REDUCE
//COUGH E??!?!?!! O.O
//uwu i see you ryan

void build(int v, int l, int r, vi &gap, vvi &seg){
    if(l == r){
        seg[v].push_back(gap[l]);
        return;
    }

    int mid = l + (r-l)/2;
    build(v*2, l, mid, gap, seg);
    build(v*2+1, mid+1, r, gap, seg);

    int ind = l, ind2 = mid+1;
    while(ind <= mid && ind2 <= r){
        if(gap[ind] < gap[ind2]){
            seg[v].push_back(gap[ind]);
            ind++;
        }else{
            seg[v].push_back(gap[ind2]);
            ind2++;
        }
    }

    while(ind <= mid){
        seg[v].push_back(gap[ind]);
        ind++;
    }

    while(ind2 <= r){
        seg[v].push_back(gap[ind2]);
        ind2++;
    }

    for(int i = l; i <= r; ++i)
        gap[i] = seg[v][i-l];
}

int query(int v, int bound, int l, int r, int lq, int rq, vvi &seg){
    if(l > r || lq > r || rq < l)
        return 0;
    else if(lq <= l && r <= rq){
        return seg[v].end() - lower_bound(all(seg[v]), bound);
    }else{
        int mid = l + (r-l)/2;
        return query(v*2, bound, l, mid, lq, rq, seg) + query(v*2+1, bound, mid+1, r, lq, rq, seg);
    }
}

void solve() {
    int n;
    cin >> n;
    string s;
    cin >> s;

    vi a(n);
    rep(i, 0, n)
        cin >> a[i];

    int q;
    cin >> q;

    vi prew(n+1), prem(n+1);
    rep(i, 0, n){
        prew[i+1] = prew[i] + (s[i] == 'W');
        prem[i+1] = prem[i] + (s[i] == 'M');
    }

    vi tom(n, 3ll*LINF);
    int pl = -1;
    for(int i = n-1; i >= 0; --i){
        if(s[i] == 'M')
            pl = a[i];
        else{
            if(pl != -1){
                tom[i] = pl - a[i];
            }
        }
    }
    sparseTable<int> mintom(tom);

    vi gap(n, -1);
    pl = -1;
    for(int i = n-1; i >= 0; --i){
        if(s[i] == 'W'){
            if(pl != -1){
                gap[i] = pl - a[i];
            }
            pl = a[i];
        }
    }

    vi wind, mind;
    for(int i{}; i < n; ++i)
        if(s[i] == 'W')
            wind.push_back(i);
        else
            mind.push_back(i);

    vvi seg(4*n);
    build(1, 0, n-1, gap, seg);

    while(q--){
        int l, r;
        cin >> l >> r;

        l--, r--;

        if(prew[r+1] - prew[l] == r-l+1){
            cout << 1 << ' ' << -1 << '\n';
            continue;
        }

        if(prem[r+1] - prem[l] == r-l+1){
            cout << 0 << ' ' << -1 << '\n';
            continue;
        }

        // there are >= 1 Ws
        // there is >= 1 M

        auto it = upper_bound(all(mind), r);
        it--;
        int lastm = *it;

        it = upper_bound(all(wind), r);
        it--;
        int lastw = *it;

        int sep = mintom.query(l, lastm-1);

        if(sep >= 2ll*LINF){
            // this only happens if all Ms before Ws
            // MMMMWW
            cout << 1 << ' ' << -1 << '\n';
            continue;
        }
        
        int cnt = query(1, sep, 0, n-1, l, lastw-1, seg) + 1;
        cout << cnt << ' ' << sep << '\n';
    }
}

uci main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int tc; cin >> tc;
    for (int t = 1; t <= tc; t++) {
        // cout << "Case #" << t  << ": ";
        solve();
    }
}

/*
    random number generator stuff
    num = rng(); gives integer number
    num = uniform_int_distribution<int>(a, b)(rng); -> bounds [a, b]
    num = uniform_real_distribution<double>(a, b)(rng); -> bounds [a, b)
    can also instantiate distributions and call on generator:
    uniform_int_distribution<int> thing(a, b);
    num = thing(rng);
*/
// struct custom_hash {
//     static uint64_t splitmix64(uint64_t x) {
//         // http://xorshift.di.unimi.it/splitmix64.c
//         x += 0x9e3779b97f4a7c15;
//         x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
//         x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
//         return x ^ (x >> 31);
//     }
//     size_t operator()(uint64_t x) const {
//         static const uint64_t FIXED_RANDOM = lrng();
//         return splitmix64(x + FIXED_RANDOM);
//     }
// };
