#include <bits/stdc++.h>
using namespace std;
const int N = int(3e5) + 99;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    long long int a, b, p;
    cin >> a >> b >> p;
    string s;
    cin >> s;
    long long int n = s.length();
    vector<long long int> dp(n, 0);
    for (long long int i = n - 2; i >= 0; i--) {
      if (i == n - 2 && s[i] == 'A')
        dp[i] = a;
      else if (i == n - 2 && s[i] == 'B')
        dp[i] = b;
      else if ((s[i] == 'A' && s[i + 1] == 'A') ||
               (s[i] == 'B' && s[i + 1] == 'B'))
        dp[i] = dp[i + 1];
      else if (s[i] == 'A' && s[i + 1] == 'B')
        dp[i] = dp[i + 1] + a;
      else if (s[i] == 'B' && s[i + 1] == 'A')
        dp[i] = dp[i + 1] + b;
    }
    for (long long int i = 0; i < n; i++) {
      if (dp[i] <= p) {
        cout << i + 1 << endl;
        break;
      }
    }
  }
  return 0;
}
