#include <bits/stdc++.h>
using namespace std;
long long int md = 1e9 + 7;
long long int __gcd(long long int a, long long int b) {
  if (b == 0) return a;
  return __gcd(b, a % b);
}
long long int poww(long long int a, long long int b) {
  long long int res = 1;
  while (b) {
    if (b & 1) {
      res *= a;
      res %= md;
    }
    a *= a;
    a %= md;
    b >>= 1;
  }
  return res;
}
void ainp(long long int arr[], long long int n) {
  for (long long int i = 1; i <= n; i++) cin >> arr[i];
}
const long long int N = 2e5 + 5;
void solve() {
  long long int a, b, c;
  cin >> a >> b >> c;
  string s;
  cin >> s;
  long long int cost = 0;
  long long int ans = s.length() - 1;
  long long int i = s.length() - 2;
  while (i >= 0) {
    char ch;
    if (s[i] == 'A') {
      ch = 'A';
      cost += a;
    } else {
      ch = 'B';
      cost += b;
    }
    if (cost > c) break;
    while (s[i] == ch && i >= 0) {
      i--;
    }
    ans = i + 1;
  }
  ans++;
  cout << ans << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int t;
  cin >> t;
  while (t-- > 0) {
    solve();
  }
}
