#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, q;
  scanf("%d", &t);
  for (q = 1; q <= t; q++) {
    long long int a, b, c, pr = 0, bb = 1, aa = 1;
    string s;
    cin >> a >> b >> c;
    cin >> s;
    long long int n = s.length();
    for (int i = n - 2; i >= 0; i--) {
      if (s[i] == 'B' and bb == 1) {
        bb = 0;
        aa = 1;
        if (c < b) {
          cout << i + 2 << endl;
          pr = 1;
          break;
        } else
          c -= b;
      } else if (s[i] == 'A' and aa == 1) {
        aa = 0;
        bb = 1;
        if (c < a) {
          cout << i + 2 << endl;
          pr = 1;
          break;
        } else
          c -= a;
      }
    }
    if (!pr) cout << 1 << endl;
  }
  return 0;
}
