#include <bits/stdc++.h>
using namespace std;
long long a, b, p, zo;
char o[(int)1e5 + 10];
long long idx[(int)1e5 + 10];
long long sum[(int)1e5 + 10];
int main(void) {
  long long q;
  scanf("%lld", &q);
  while (q--) {
    scanf("%lld %lld %lld %s", &a, &b, &p, o + 1);
    zo = 1;
    long long ans = 1;
    for (long long i = 1; o[i + 1]; i++) {
      ans++;
      if (o[i - 1] != o[i]) {
        o[zo] = o[i];
        idx[zo] = i;
        zo++;
      }
    }
    sum[zo] = 0;
    for (long long i = zo - 1; 0 < i; i--) {
      if (o[i] == 'A')
        sum[i] = a;
      else
        sum[i] = b;
      sum[i] += sum[i + 1];
      if (sum[i] <= p) {
        ans = idx[i];
      }
    }
    printf("%lld\n", ans);
  }
}
