#include <bits/stdc++.h>
using namespace std;
string s;
int a, b, n;
long long p;
int main() {
  int t;
  cin >> t;
  int j;
  while (t--) {
    cin >> a >> b >> p;
    long long sum = 0;
    cin >> s;
    n = s.length();
    s = '*' + s;
    for (int i = 1; i <= n;) {
      j = i;
      while (j <= n && s[j] == s[i]) j++;
      sum += (long long)(s[i] == 'A' ? a : b);
      i = j;
      if (i == n) break;
    }
    int i;
    for (i = 1; i <= n;) {
      if (sum <= p) break;
      j = i;
      while (j <= n && s[j] == s[i]) j++;
      sum -= (long long)(s[i] == 'A' ? a : b);
      i = j;
      if (i == n) break;
    }
    cout << min(i, n) << endl;
  }
  return 0;
}
