#include <bits/stdc++.h>
using namespace std;
int t, a, b, p;
string s;
bool can(int num) {
  int sum = 0;
  char curc = 'A';
  while (num != s.length() - 1) {
    if (s[num] == 'A') {
      curc = 'A';
    } else {
      curc = 'B';
    }
    while (s[num] == curc) {
      num++;
      if (num == s.length() - 1) break;
    }
    sum += (curc == 'A' ? a : b);
    curc = (curc == 'A' ? 'B' : 'A');
    if (sum > p) return false;
  }
  return true;
}
int main() {
  cin >> t;
  vector<int> ans;
  for (int i = 0; i < t; i++) {
    cin >> a >> b >> p;
    cin >> s;
    int l = 0;
    int r = s.length() - 1;
    int m = (l + r) / 2;
    while (l != r - 1) {
      if (can(m)) {
        r = m;
      } else {
        l = m;
      }
      m = (l + r) / 2;
    }
    if (can(l)) {
      ans.push_back(l + 1);
    } else {
      ans.push_back(r + 1);
    }
  }
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i] << '\n';
  }
  return 0;
}
