#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long a, b, p, cost = 0;
    string s;
    int flag = 0;
    cin >> a >> b >> p >> s;
    if (s[s.length() - 2] == 'A')
      cost = a;
    else
      cost = b;
    if (cost > p) {
      cout << s.length() << "\n";
      continue;
    }
    for (int i = s.length() - 3; i >= 0; i--) {
      if (s[i] == s[i + 1])
        continue;
      else if (s[i] == 'A')
        cost += a;
      else
        cost += b;
      if (cost > p) {
        if (s[i] == 'A')
          cost -= a;
        else
          cost -= b;
        cout << i + 2 << endl;
        flag = 1;
        break;
      }
    }
    if (flag == 0) cout << 1 << "\n";
  }
  return 0;
}
