#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int TC;
  cin >> TC;
  while (TC--) {
    long long a, b, p;
    cin >> a >> b >> p;
    string s;
    cin >> s;
    int r = s.length();
    long long m = (s[r - 1] == 'A') ? a : b;
    if (s[r - 1] != s[r - 2]) {
      m = 0;
    }
    for (int i = s.length() - 2; i >= 0; i--) {
      if (s[i] != s[i + 1]) {
        m += ((s[i] == 'A') ? a : b);
      }
      if (m <= p) {
        r = i + 1;
      }
    }
    cout << r << "\n";
  }
}
