#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
long long n, k, t, m, q, flag = 0;
long long po(long long k, long long n, long long ans, long long temp,
             long long ans1) {
  if (n == 0) return ans;
  while (temp <= n) {
    ans *= ans1;
    ans %= mod;
    ans1 = ans1 * ans1;
    ans1 %= mod;
    n = n - temp;
    temp *= 2;
  }
  return po(k, n, ans, 1, k) % mod;
}
long long min(long long a, long long b) {
  if (a > b)
    return b;
  else
    return a;
}
long long max(long long a, long long b) {
  if (a > b)
    return a;
  else
    return b;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  while (t--) {
    long long a, b, p;
    cin >> a >> b >> p;
    string s;
    cin >> s;
    n = s.size();
    long long ans = n;
    long long temp = 0;
    for (int i = n - 2; i >= 0; i--) {
      if (i == n - 2) {
        if (s[i] == 'A')
          temp += a;
        else
          temp += b;
      } else if (s[i] == s[i + 1])
        ;
      else if (s[i] == 'B')
        temp += b;
      else
        temp += a;
      if (temp <= p) ans = i + 1;
    }
    cout << ans << "\n";
  }
  return 0;
}
