#include <bits/stdc++.h>
using namespace std;
int a, b, p;
char str[100005];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie();
  int t;
  cin >> t;
  while (t--) {
    cin >> a >> b >> p >> str;
    int len = strlen(str);
    int res = len;
    bool bus = (str[len - 2] == 'A');
    int sum = (bus) ? a : b;
    for (int i = len - 2; i >= 0; --i) {
      if (bus && str[i] == 'B') {
        sum += b;
        bus = false;
      } else if (!bus && str[i] == 'A') {
        sum += a;
        bus = true;
      }
      if (sum > p) {
        break;
      }
      res = i + 1;
    }
    cout << res << "\n";
  }
  return 0;
}
