#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
char s[N];
long long dp[N];
int _, n, a, b, p, f[N][2];
int main() {
  for (scanf("%d", &_); _--;) {
    scanf("%d%d%d%s", &a, &b, &p, s), n = strlen(s);
    for (int i = n - 1; i >= 0; i--) {
      if (i) f[i - 1][s[i] - 'A'] = i;
      for (int j = 0; j < 2; j++)
        if (!f[i][j]) f[i][j] = f[i + 1][j];
    }
    dp[n - 1] = 0;
    for (int i = n - 2; i >= 0; i--) {
      int j = f[i][1 - (s[i] - 'A')];
      dp[i] = dp[j] + (s[i] == 'A' ? a : b);
    }
    for (int i = 0; i < n; i++)
      if (dp[i] <= p) {
        printf("%d\n", i + 1);
        break;
      }
    for (int i = 0; i <= n + 2; i++) f[i][0] = f[i][1] = dp[i] = 0;
  }
}
