#include <bits/stdc++.h>
#pragma GCC optimize("O2,Ofast,inline,unroll-all-loops,-ffast-math")
using namespace std;
const int INF = 1e9 + 7;
int q;
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  cin >> q;
  while (q--) {
    long long a, b, p;
    string s;
    cin >> a >> b >> p >> s;
    vector<pair<int, long long> > A;
    int n = s.size();
    A.push_back({(int)n - 1, 0});
    long long sumcoin = 0;
    for (int i = n - 2; i >= 0; --i) {
      if (s[i] == 'A')
        sumcoin += a;
      else
        sumcoin += b;
      int j = i;
      while (s[j - 1] == s[i] && j - 1 >= 0) --j;
      A.push_back({j, sumcoin});
      i = j;
    }
    for (auto it = A.rbegin(); it != A.rend(); ++it) {
      if (it->second <= p) {
        cout << (int)it->first + 1 << endl;
        break;
      }
    }
  }
  return 0;
}
