#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long a, b, p;
  cin >> a >> b >> p;
  string s;
  cin >> s;
  long long c = 0;
  long long i;
  for (i = s.size() - 2; i >= 0; i--) {
    if (c != s[i]) {
      c = s[i];
      if (s[i] == 'A') p -= a;
      if (s[i] == 'B') p -= b;
    }
    if (p < 0) break;
  }
  cout << i + 2 << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  clock_t start, end;
  start = clock();
  long long tc;
  cin >> tc;
  for (long long i = 1; i <= tc; i++) solve();
  end = clock();
  double time_taken = double(end - start) / double(CLOCKS_PER_SEC);
}
