#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  cin >> t;
  while (t--) {
    long long int a, b, p, i;
    cin >> a >> b >> p;
    string s;
    cin >> s;
    long long int n = s.length();
    long long int prev;
    if (s[n - 2] == 'A')
      prev = a;
    else
      prev = b;
    if (prev > p) {
      cout << n << "\n";
      continue;
    }
    for (i = n - 3; i > -1; i--) {
      if (s[i] != s[i + 1]) {
        if (s[i] == 'A')
          prev += a;
        else
          prev += b;
      }
      if (prev > p) break;
    }
    cout << i + 2 << "\n";
  }
  return 0;
}
