#include <bits/stdc++.h>
using namespace std;
void solve() {
  int a, b, p;
  string s;
  cin >> a >> b >> p >> s;
  int ans = s.length();
  char el = s[ans - 1];
  if (p < b && s[ans - 1] == s[ans - 2] == 'B') {
    cout << ans << endl;
    return;
  }
  if (p < a && s[ans - 1] == s[ans - 2] == 'A') {
    cout << ans << endl;
    return;
  }
  for (int i = s.length() - 2; i >= 0; i--) {
    if (i == s.length() - 2) {
      p -= (s[i] == 'B' ? b : a);
      el = s[i];
    } else {
      if (s[i] != el) {
        p -= (s[i] == 'B' ? b : a);
        el = s[i];
      }
    }
    if (p < 0) {
      cout << i + 2 << endl;
      return;
    } else
      ans = i + 1;
  }
  cout << 1 << endl;
}
int main() {
  int t;
  cin >> t;
  while (t--) solve();
}
