#include <bits/stdc++.h>
using namespace std;
struct pair_hash {
  template <class T1, class T2>
  std::size_t operator()(const std::pair<T1, T2>& pair) const {
    return std::hash<T1>()(pair.first) ^ std::hash<T2>()(pair.second);
  }
};
const long double EPS = 0.000001;
const long long MOD = 1000000007;
const long long INF = 1e18;
const double pi = 2 * acos(0.0);
long long n, m, k, p, q, t, sum = 0, cnt = 0;
long long mx = INT64_MIN;
long long mn = INT64_MAX;
bool flag = 0;
vector<long long> v;
string s = "", s1, s2;
void bad_solve() {}
void solve() {
  cin >> t;
  while (t--) {
    cin >> p >> q >> k >> s;
    n = s.size();
    vector<long long> pref(n, 0);
    char ta = s[0];
    pref[0] = (ta == 'A' ? p : q);
    for (long long(i) = (1); (i) < (n); ++(i)) {
      pref[i] += pref[i - 1];
      if (s[i] != ta && i != n - 1) {
        ta = s[i];
        pref[i] += (ta == 'A' ? p : q);
      }
    }
    sum = pref[n - 1];
    if (sum <= k)
      cout << 1 << endl;
    else {
      for (long long(i) = 0; (i) < (n); ++(i)) {
        if (sum - pref[i] <= k) {
          long long tt = pref[i];
          while (i < n - 1 && pref[i] == tt) ++i;
          cout << i + 1 << endl;
          break;
        }
      }
    }
  }
}
int main() {
  cout.precision(20);
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
