#include <bits/stdc++.h>
using namespace std;
int sol(int a, int b, int p, string s) {
  int cost = s[s.size() - 2] == 'A' ? a : b;
  if (cost > p) return s.size();
  for (int i = s.size() - 2; i > 0; i--) {
    if (s[i - 1] != s[i]) {
      cost += s[i - 1] == 'A' ? a : b;
      if (cost > p) return i + 1;
    }
  }
  return 1;
}
int main(int argn, char** argc) {
  string line;
  getline(cin, line);
  int n = stoi(line);
  while (n--) {
    getline(cin, line);
    istringstream ss(line);
    int a, b, p;
    ss >> a;
    ss >> b;
    ss >> p;
    getline(cin, line);
    cout << sol(a, b, p, line) << endl;
  }
}
