#include <bits/stdc++.h>
using namespace std;
bool isprime(long long n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (long long i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long a, b, p;
    cin >> a >> b >> p;
    string s;
    cin >> s;
    long long second = s.size();
    long long sum = 0, index = -1;
    for (long long i = second - 2; i >= 0; i--)
      if (s[i] != s[i + 1]) {
        if (i != second - 2) {
          if (s[i + 1] == 'A')
            sum = a;
          else
            sum = b;
        }
        break;
      }
    if (sum > p) {
      cout << second << "\n";
      continue;
    }
    for (long long i = second - 2; i >= 0; i--) {
      if (s[i] != s[i + 1]) {
        long long pres;
        if (s[i] == 'A')
          pres = a;
        else
          pres = b;
        if (sum + pres <= p)
          sum += pres;
        else {
          index = i + 1;
          break;
        }
      }
    }
    long long ans = index;
    if (index == -1) {
      long long pres;
      if (s[0] == 'A')
        pres = a;
      else
        pres = b;
      if (pres > p) ans = second - 1;
    }
    if (ans == -1)
      cout << 1 << "\n";
    else
      cout << ans + 1 << "\n";
  }
  return 0;
}
