#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
string itos(int n) {
  stringstream ss;
  ss << n;
  string second = ss.str();
  return second;
}
long long ppow(long long x, long long y, long long mod) {
  long long res = 1;
  while (y) {
    if (y & 1) res = res * x % mod;
    y >>= 1;
    x = x * x % mod;
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    long long a, b, p;
    cin >> a >> b >> p;
    string second;
    cin >> second;
    int n = second.size();
    vector<long long> dp(n + 1, 0);
    int last = n;
    if (second.back() == 'A')
      second += 'B';
    else
      second += 'A';
    for (int i = n - 2; i >= 0; --i) {
      if (second[i] != second[i + 1]) {
        last = i + 1;
      }
      if (second[last] == 'A') {
        dp[i] = b + dp[last];
      } else
        dp[i] = a + dp[last];
    }
    int ans;
    for (int i = 0; i < n; ++i) {
      if (dp[i] <= p) {
        ans = i;
        break;
      }
    }
    cout << ans + 1 << "\n";
  }
}
