#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long q;
  cin >> q;
  while (q--) {
    long long a, b, p;
    cin >> a >> b >> p;
    string s;
    cin >> s;
    long long n = s.length();
    long long lo = 0, hi = n;
    while (lo <= hi) {
      long long mid = (lo + hi) >> 1;
      long long res = 0;
      for (long long i = mid; i < n; i++) {
        long long j = i;
        while (j < n && s[j] == s[i]) {
          ++j;
        }
        if (j == n && j - i <= 1) {
          i = j - 1;
          continue;
        }
        if (s[i] == 'A') {
          res += a;
        } else {
          res += b;
        }
        i = j - 1;
      }
      if (res > p) {
        lo = mid + 1;
      } else {
        hi = mid - 1;
      }
    }
    cout << lo + 1 << endl;
  }
  return 0;
}
