#include <bits/stdc++.h>
using namespace std;
map<int, map<int, vector<int>>> answers;
int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    int bus, tram, money;
    cin >> bus >> tram >> money;
    string s;
    cin >> s;
    int cur = s.size() - 2;
    while (true) {
      char cur_char = s[cur];
      if (cur_char == 'A') {
        if (bus > money) {
          cout << cur + 2 << '\n';
          break;
        }
        money -= bus;
      }
      if (cur_char == 'B') {
        if (tram > money) {
          cout << cur + 2 << '\n';
          break;
        }
        money -= tram;
      }
      while (cur >= 0 && s[cur] == cur_char) {
        cur -= 1;
      }
      if (cur == -1) {
        cout << 1 << '\n';
        break;
      }
    }
  }
  return 0;
}
