#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long a, b, c;
    cin >> a >> b >> c;
    string s;
    cin >> s;
    long long n = s.length();
    long long i = n - 2, summ = 0;
    long long end = n - 1;
    while (i >= 0) {
      if (i == 0) {
        if (s[i] == 'A')
          summ += a;
        else
          summ += b;
        if (summ <= c) end = i;
        break;
      }
      if (s[i] != s[i - 1]) {
        if (s[i] == 'A')
          summ += a;
        else
          summ += b;
        if (summ > c)
          break;
        else
          end = i;
      }
      i--;
    }
    cout << end + 1 << endl;
  }
}
