#include <bits/stdc++.h>
using namespace std;
const int N = 1e9 + 7;
long long int possible(string s, int a, int b, int p, int mid) {
  char tofind;
  long long int cnt = 0;
  if (s[mid] == 'A') {
    tofind = 'B';
  } else
    tofind = 'A';
  for (int i = mid + 1; i < s.length(); i++) {
    if (i == s.length() - 1 && s[i] != tofind && tofind == 'A') {
      cnt += b;
    }
    if (i == s.length() - 1 && s[i] != tofind && tofind == 'B') {
      cnt += a;
    }
    if (tofind == 'A' && s[i] == 'A') {
      cnt += b;
      tofind = 'B';
    }
    if (tofind == 'B' && s[i] == 'B') {
      cnt += a;
      tofind = 'A';
    }
  }
  if (cnt <= p) {
    return mid;
  } else {
    return -1;
  }
}
long long int binary(string s, int a, int b, int p) {
  int iteration = 1;
  int l = 0;
  int h = s.length() - 1;
  long long int ans = -1e9;
  long long int cnt = 0;
  long long int mid;
  while (l <= h) {
    mid = l + (h - l) / 2;
    if (possible(s, a, b, p, mid) != -1) {
      ans = mid;
      h = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  return ans;
}
void solve() {
  long long int a, b, p;
  cin >> a >> b >> p;
  string s;
  cin >> s;
  long long int ans = binary(s, a, b, p);
  if (ans != -1e9) {
    cout << ans + 1;
  } else {
    cout << s.length();
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int t;
  cin >> t;
  while (t--) {
    solve();
    cout << endl;
  }
}
