#include <bits/stdc++.h>
using namespace std;
char s[1000010];
int aa[1000010], bb[1000010];
bool cmp(int a, int b) { return a > b; }
int main() {
  ios::sync_with_stdio(0);
  int t;
  cin >> t;
  while (t--) {
    int a, b, p;
    cin >> a >> b >> p;
    int ppp = p;
    cin >> (s + 1);
    int len = strlen(s + 1);
    long long ans = 0;
    int flag = 1;
    if (s[len] != s[len - 1]) {
      ans = len, flag = 1, p = ppp;
      for (int i = len - 1; i; i--) {
        if (s[i] == 'A') {
          if (p < a)
            flag = 0;
          else {
            int j = i;
            while (s[j] == 'A' && j) j--;
            p -= a;
            if (p >= b)
              ans = j;
            else
              ans = j + 1;
            i = j + 1;
          }
        } else if (s[i] == 'B') {
          if (p < b)
            flag = 0;
          else {
            int j = i;
            while (s[j] == 'B' && j) j--;
            p -= b;
            if (p >= a)
              ans = j;
            else
              ans = j + 1;
            i = j + 1;
          }
        }
        if (!flag) {
          break;
        }
      }
      if (!ans) ans++;
      cout << ans << endl;
    } else {
      ans = len, flag = 1, p = ppp;
      for (int i = len; i; i--) {
        if (s[i] == 'A') {
          if (p < a)
            flag = 0;
          else {
            int j = i;
            while (s[j] == 'A' && j) j--;
            p -= a;
            if (p >= b)
              ans = j;
            else
              ans = j + 1;
            i = j + 1;
          }
        } else if (s[i] == 'B') {
          if (p < b)
            flag = 0;
          else {
            int j = i;
            while (s[j] == 'B' && j) j--;
            p -= b;
            if (p >= a)
              ans = j;
            else
              ans = j + 1;
            i = j + 1;
          }
        }
        if (!flag) {
          break;
        }
      }
      if (!ans) ans++;
      cout << ans << endl;
    }
  }
  return 0;
}
