#include <bits/stdc++.h>
using namespace std;
using lli = int64_t;
int greedy(string s, int a, int b, int money, int index) {
  int64_t cost = 0;
  char prev = s[index];
  if (prev == 'A') {
    cost += (int64_t)a;
  } else {
    cost += (int64_t)b;
  }
  for (int i = index + 1; i < (int)s.size() - 1; i++) {
    if (prev == s[i]) {
      continue;
    } else {
      prev = s[i];
      if (s[i] == 'A') {
        cost += (int64_t)a;
      } else {
        cost += (int64_t)b;
      }
    }
  }
  if (cost <= money) {
    return true;
  }
  return false;
}
int Binary_Search(string s, int a, int b, int money) {
  int l = 0, r = (int)s.size() - 1;
  int ans = r;
  while (l <= r) {
    int mid = l + (r - l) / 2;
    if (greedy(s, a, b, money, mid)) {
      r = mid - 1;
      ans = min(ans, mid);
    } else {
      l = mid + 1;
    }
  }
  return ans + 1;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int T;
  cin >> T;
  for (int t = 1; t <= T; t++) {
    int a, b, money;
    string s;
    cin >> a >> b >> money >> s;
    cout << Binary_Search(s, a, b, money) << "\n";
  }
}
