#include <bits/stdc++.h>
#pragma optimize("-O3")
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  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> v(n);
    long long int sum = 0;
    for (long long int i = 1; i < n; i++) {
      if (i == n - 1) {
        if (s[i - 1] == 'A') {
          sum += a;
        } else if (s[i - 1] == 'B') {
          sum += b;
        }
      } else {
        if (s[i - 1] == 'A' && s[i] == 'B') {
          sum += a;
        } else if (s[i - 1] == 'B' && s[i] == 'A') {
          sum += b;
        }
      }
    }
    v[0] = sum;
    for (long long int i = 1; i < n - 1; i++) {
      if (s[i - 1] == s[i]) {
        v[i] = v[i - 1];
      } else if (s[i - 1] == 'A' && s[i] == 'B') {
        v[i] = sum - a;
        sum -= a;
      } else if (s[i - 1] == 'B' && s[i] == 'A') {
        v[i] = sum - b;
        sum -= b;
      }
    }
    long long int j;
    for (j = 0; j < n; j++) {
      if (v[j] <= p) {
        cout << j + 1 << "\n";
        break;
      }
    }
    if (j == n) {
      cout << n << "\n";
    }
  }
  return 0;
}
