#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    string s;
    char c;
    int a, b, p, n, x = 1;
    cin >> a >> b >> p >> s;
    n = s.length(), c = '.';
    for (int i = n - 2; i >= 0; i--) {
      if (s[i] != c) {
        if (s[i] == 'A' && p >= a)
          p -= a;
        else if (s[i] == 'B' && p >= b)
          p -= b;
        else {
          x = i + 2;
          break;
        }
        c = s[i];
      }
    }
    cout << x << "\n";
  }
  return 0;
}
