#include <algorithm>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <iostream>
#include <map>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

using namespace __gnu_pbds;
template<typename T> using OrderedSet = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

int main() {
  int T, N, Q;
  for (cin >> T; T--;) {
    string S;
    cin >> N >> S;
    vector<int64_t> T(N);
    for (auto& x : T) cin >> x;
    cin >> Q;
    vector<tuple<int,int,int,int,int64_t>> q;
    for (int i = 0, l, r; i < Q; i++) {
      cin >> l >> r; l--;
      q.emplace_back(i, l, r, 1, 2e18);
    }

    sort(q.begin(), q.end(), [](auto const& a, auto const& b) { return get<2>(a) < get<2>(b); });
    map<int64_t,int64_t> hull;
    for (int qi = 0, wi = 0; qi < Q; qi++) {
      auto& [_,l,r,nw,d] = q[qi];
      for (; wi+1 < r; wi++) if (S[wi] == 'W' && S[wi+1] == 'M') {
        auto it = hull.upper_bound(T[wi]);
        if (it == hull.end() || it->second > T[wi+1]-T[wi]) {
          while (it != hull.begin()) {
            --it;
            if (T[wi+1]-T[wi] <= it->second) hull.erase(it++); else break;
          }
          hull[T[wi]] = T[wi+1]-T[wi];
        }
      }
      auto it = hull.lower_bound(T[l]);
      if (it != hull.end()) d = it->second;
    }

    OrderedSet<pair<int64_t,int>> dist;
    for (int qi = 0, wi = 0, lastw = -1; qi < Q; qi++) {
      auto& [_,l,r,nw,d] = q[qi];
      for (; wi < r; wi++) if (S[wi] == 'W') {
        if (lastw != -1) dist.insert({T[wi]-T[lastw], wi});
        lastw = wi;
      }
      nw += dist.size() - dist.order_of_key({d, 0});
    }

    dist.clear();
    sort(q.begin(), q.end(), [](auto const& a, auto const& b) { return get<1>(a) < get<1>(b); });
    for (int qi = 0, wi = 0, lastw = -1; qi < Q; qi++) {
      auto& [_,l,r,nw,d] = q[qi];
      for (; wi < N && lastw < l; wi++) if (S[wi] == 'W') {
        if (lastw != -1) dist.insert({T[wi]-T[lastw], wi});
        lastw = wi;
      }
      nw -= dist.size() - dist.order_of_key({d, 0});
      if (lastw < l || lastw >= r) nw = 0;
    }

    sort(q.begin(), q.end());
    for (auto [i,l,r,nw,d] : q) cout << nw << ' ' << (d == 2e18 ? -1 : d) << endl;
  }
}
