#include <bits/stdc++.h>
using namespace std;
int a, b, p;
int n;
char s[100010];
int main() {
  int T;
  scanf("%d", &T);
  for (int ii = 0; ii < T; ii++) {
    scanf("%d%d%d\n", &a, &b, &p);
    scanf("%s\n", s);
    n = strlen(s);
    int q = n - 2;
    int cost = 0;
    int pos = n;
    char formerCh = ' ';
    while (q >= 0) {
      if (s[q] != formerCh) {
        int newCost = cost;
        formerCh = s[q];
        if (s[q] == 'A') {
          newCost = newCost + a;
        } else {
          newCost = newCost + b;
        }
        if (newCost > p) {
          break;
        }
        cost = newCost;
      }
      pos = q + 1;
      q--;
    }
    printf("%d\n", pos);
  }
  return 0;
}
