#include <bits/stdc++.h>
using namespace std;
int t;
int a, b, p;
string st;
int main() {
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  string tg;
  for (int ct = 1; ct <= t; ct++) {
    cin >> a >> b >> p;
    getline(cin, tg);
    getline(cin, st);
    st = ' ' + st;
    int n = st.size() - 1;
    int rei = n;
    int res = 0;
    for (int i = n - 1; i >= 1; i--)
      if (st[i] == st[i + 1])
        rei = i;
      else
        break;
    if (rei != n)
      if (st[rei] == 'A')
        if (a <= p)
          res += a;
        else {
          cout << n << '\n';
          continue;
        }
      else {
        if (b <= p)
          res += b;
        else {
          cout << n << '\n';
          continue;
        }
      }
    for (int i = rei - 1; i >= 1; i--)
      if (st[i] != st[i + 1]) {
        if (st[i] == 'A') {
          if (res + a <= p) {
            res += a;
            rei = i;
          } else
            break;
        } else {
          if (res + b <= p) {
            res += b;
            rei = i;
          } else
            break;
        }
      }
    for (int i = rei - 1; i >= 1; i--)
      if (st[i] == st[i + 1])
        rei = i;
      else
        break;
    cout << rei << '\n';
  }
  return 0;
}
