/**
 *    author:  tourist
 *    created: 21.10.2026 18:57:24
**/
#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif

template <typename T, typename F>
class SparseTable {
 public:
  int n;
  vector<vector<T>> mat;
  F func;

  SparseTable(const vector<T>& a, const F& f) : func(f) {
    n = static_cast<int>(a.size());
    int max_log = 32 - __builtin_clz(n);
    mat.resize(max_log);
    mat[0] = a;
    for (int j = 1; j < max_log; j++) {
      mat[j].resize(n - (1 << j) + 1);
      for (int i = 0; i <= n - (1 << j); i++) {
        mat[j][i] = func(mat[j - 1][i], mat[j - 1][i + (1 << (j - 1))]);
      }
    }
  }

  T get(int from, int to) const {
    assert(0 <= from && from <= to && to <= n - 1);
    int lg = 32 - __builtin_clz(to - from + 1) - 1;
    return func(mat[lg][from], mat[lg][to - (1 << lg) + 1]);
  }
};

template <typename T>
class FenwickTree {
 public:
  vector<T> fenw;
  int n;
  int pw;

  FenwickTree() : n(0) {}
  FenwickTree(int n_) : n(n_) {
    fenw.resize(n);
    pw = 1;
    while (2 * pw <= n) {
      pw *= 2;
    }
  }

  void Modify(int x, T v) {
    assert(0 <= x && x <= n);
    while (x < n) {
      fenw[x] += v;
      x |= x + 1;
    }
  }

  T Query(int x) {
    assert(0 <= x && x <= n);
    T v{};
    while (x > 0) {
      v += fenw[x - 1];
      x &= x - 1;
    }
    return v;
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int tt;
  cin >> tt;
  while (tt--) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<int64_t> t(n);
    for (int i = 0; i < n; i++) {
      cin >> t[i];
    }
    const int64_t inf = int64_t(2e18);
    vector<int64_t> d(n, inf);
    for (int i = 0; i < n - 1; i++) {
      if (s[i] == 'W' && s[i + 1] == 'M') {
        d[i + 1] = t[i + 1] - t[i];
      }
    }
    SparseTable st(d, [&](int64_t x, int64_t y) {
      return min(x, y);
    });
    int q;
    cin >> q;
    vector<int> ql(q), qr(q);
    vector<int> res_m(q);
    vector<int64_t> res_d(q);
    for (int i = 0; i < q; i++) {
      cin >> ql[i] >> qr[i];
      --ql[i]; --qr[i];
      res_d[i] = inf;
      if (ql[i] < qr[i]) {
        res_d[i] = st.get(ql[i] + 1, qr[i]);
      }
    }
    vector<pair<int64_t, int>> ev;
    for (int i = 0; i < n - 1; i++) {
      if (s[i] == 'W' && s[i + 1] == 'W') {
        ev.emplace_back(t[i + 1] - t[i], i + 1);
      }
    }
    for (int i = 0; i < q; i++) {
      ev.emplace_back(res_d[i], ~i);
    }
    FenwickTree<int> fenw(n);
    for (int i = 0; i < n; i++) {
      if (s[i] == 'W') {
        fenw.Modify(i, +1);
      }
    }
    sort(ev.begin(), ev.end());
    for (auto [_, id] : ev) {
      if (id >= 0) {
        fenw.Modify(id, -1);
      } else {
        id = ~id;
        res_m[id] = fenw.Query(qr[id] + 1) - fenw.Query(ql[id] + 1);
        if (s[ql[id]] == 'W') {
          res_m[id] += 1;
        }
      }
    }
    for (int i = 0; i < q; i++) {
      cout << res_m[i] << " " << (res_d[i] == inf ? -1 : res_d[i]) << '\n';
    }
  }
  return 0;
}
