#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long t;
  cin >> t;
  while (t--) {
    long long i, tot = 0, curt = 0, flag = 1, near;
    string s;
    char cur = 'c';
    long long a, b, p, c;
    cin >> a >> b >> p >> s;
    for (i = 0; i < s.length() - 1; i++) {
      if (cur != s[i]) {
        if (s[i] == 'A') {
          cur = 'A';
          tot += a;
        } else {
          cur = 'B';
          tot += b;
        }
      }
    }
    cur = 'c';
    for (i = 0; i < s.length(); i++) {
      if (s[i] != cur) {
        if (tot - curt <= p) {
          near = i;
          flag = -1;
          break;
        } else {
          if (s[i] == 'A') {
            cur = 'A';
            curt += a;
          } else {
            cur = 'B';
            curt += b;
          }
        }
      }
    }
    if (flag == -1)
      cout << near + 1 << "\n";
    else
      cout << s.length() << "\n";
  }
}
