#include <bits/stdc++.h>
using namespace std;
using DO = double;
using INT = long long;
using pii = pair<int, int>;
using pi3 = pair<pii, int>;
int power(int a, int b, int mod, int ans = 1) {
  for (; b; b >>= 1, a = 1LL * a * a % mod)
    if (b & 1) ans = 1LL * ans * a % mod;
  return ans;
}
char s[100100];
int main() {
  int t;
  cin >> t;
  while (t--) {
    int a, b, p;
    scanf("%d%d%d", &a, &b, &p);
    scanf("%s", s + 1);
    int ans = 1;
    int n = strlen(s + 1);
    for (int i = n; i; i--) {
      if (s[i - 1] == 'B') {
        if (p >= b) {
          p -= b;
          while (s[i - 1] == 'B' and i > 1) i--;
          if (i == 1) break;
          i++;
        } else {
          ans = i;
          break;
        }
      } else {
        if (p >= a) {
          p -= a;
          while (s[i - 1] == 'A' and i > 1) i--;
          if (i == 1) break;
          i++;
        } else {
          ans = i;
          break;
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
