#include <bits/stdc++.h>
using namespace std;
int read() {
  int res = 0, f = 1;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-') f = -1, c = getchar();
  while (isdigit(c)) res = (res << 3) + (res << 1) + (c ^ 48), c = getchar();
  return res * f;
}
const int maxn = 1e5 + 10;
int a, b, p;
char s[maxn];
int main() {
  int T = read();
  while (T--) {
    a = read();
    b = read();
    p = read();
    scanf("%s", s + 1);
    int tmp = 0, pos = strlen(s + 1);
    while (pos > 1) {
      int y = pos - 1;
      while (y > 1 && s[y] == s[y - 1]) y--;
      int co = (s[y] == 'A' ? a : b);
      if (tmp + co <= p) {
        tmp += co;
        pos = y;
      } else
        break;
    }
    printf("%d\n", pos);
  }
  return 0;
}
