#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int a, b, p;
    cin >> a >> b >> p;
    string s;
    cin >> s;
    int len = s.size();
    int pos = 0;
    char ss = 'C';
    for (int i = len - 2; i >= 0; i--) {
      if (ss != s[i]) {
        p -= (s[i] == 'A' ? a : b);
        ss = s[i];
        if (p < 0) {
          pos = i + 1;
          break;
        }
      }
    }
    cout << pos + 1 << "\n";
  }
  return 0;
}
