#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  string s;
  cin >> t;
  while (t--) {
    long long a, b, p, i, cost = 0, p1 = 0, q = 0, ans = 0, count = 0;
    cin >> a >> b >> p;
    cin >> s;
    long long d = s.length();
    for (i = d - 2; i >= 0; i--) {
      if (s[i] == 'A') {
        if (p1 == 0) {
          p1 = 1;
          q = 0;
          cost += a;
        }
      }
      if (s[i] == 'B') {
        if (q == 0) {
          p1 = 0;
          q = 1;
          cost += b;
        }
      }
      if (cost > p) break;
    }
    cout << i + 2 << endl;
  }
}
