#include <bits/stdc++.h>
using namespace std;
int gcd(int x, int y) {
  if (y == 0) return x;
  return gcd(y, x % y);
}
bool prime(int a) {
  long long int i, j, k, m, n, ct;
  string s;
  for (i = 2; i <= sqrt(a); i++) {
    if (a % i == 0) return false;
  }
  return true;
}
vector<int> prime_factorise(int a) {
  long long int i, j, k, m, n, ct;
  string s;
  vector<int> pr;
  for (i = 2; i <= sqrt(a); i++) {
    if (a % i == 0) {
      if (prime(i)) pr.push_back(i);
      if (prime(a / i)) pr.push_back(a / i);
    }
  }
  return pr;
}
int main() {
  long long int i, j, k, m, n, ct;
  string s;
  int t;
  cin >> t;
  while (t--) {
    long long int a, b, p;
    cin >> a >> b >> p;
    cin >> s;
    n = s.length();
    long long int dp[n];
    memset(dp, 0, sizeof dp);
    ;
    dp[n - 1] = 0;
    for (i = n - 2; i >= 0; i--) {
      if (i == n - 2 || s[i] != s[i + 1]) {
        if (s[i] == 'A') dp[i] += a;
        if (s[i] == 'B') dp[i] += b;
      }
      dp[i] += dp[i + 1];
    }
    long long int ans = -1;
    for (i = 0; i < n; i++) {
      if (dp[i] <= p) {
        ans = i;
        break;
      }
    }
    if (ans != -1) {
      cout << ans + 1 << "\n";
    } else {
      cout << n << "\n";
    }
  }
  return 0;
}
