#include <bits/stdc++.h>
using namespace std;
long long i, j, k, n, m, t, x, z, y, a, b, p, arr[500007], ans;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  cin >> t;
  while (t--) {
    string s;
    cin >> a >> b >> p >> s;
    n = s.size();
    vector<long long> v;
    v.push_back(1);
    for (i = 1; i < n; i++) {
      if (s[i] != s[i - 1]) v.push_back(i + 1);
    }
    if (v.back() != n) v.push_back(n);
    long long sz = v.size();
    long long lst = n;
    for (i = sz - 1; i > 0; i--) {
      x = v[i - 1] - 1;
      if (s[x] == 'A' && p - a >= 0) {
        p -= a;
        lst = v[i - 1];
      } else if (s[x] == 'B' && p - b >= 0) {
        p -= b;
        lst = v[i - 1];
      } else
        break;
    }
    cout << lst << "\n";
  }
  return 0;
}
