#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  long long t;
  cin >> t;
  while (t--) {
    long long a, b, p;
    cin >> a >> b >> p;
    string s;
    cin >> s;
    long long n = s.size();
    long long res = n;
    long long i = n - 2;
    while (i >= 0) {
      if (s[i] == 'A' and p - a < 0) {
        break;
      }
      if (s[i] == 'B' and p - b < 0) {
        break;
      }
      if (s[i] == 'A') {
        p -= a;
        while (i >= 0 and s[i] == 'A') {
          res = i + 1;
          i--;
        }
      } else {
        p -= b;
        while (i >= 0 and s[i] == 'B') {
          res = i + 1;
          i--;
        }
      }
    }
    cout << res << endl;
  }
}
