#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t, i, a, b, p, prev, ans, ind, n, k;
  string s;
  cin >> t;
  while (t--) {
    cin >> a >> b >> p;
    cin >> s;
    vector<long long> cost, ind;
    prev = s[0];
    k = 0;
    n = s.size();
    for (i = 1; i < n; i++) {
      if (s[i] == prev) {
        if (i != n - 1) continue;
      }
      if (prev == 'A') {
        cost.push_back(a);
        ind.push_back(k);
      } else {
        cost.push_back(b);
        ind.push_back(k);
      }
      prev = s[i];
      k = i;
    }
    int l = cost.size();
    for (i = l - 2; i >= 0; i--) {
      cost[i] += cost[i + 1];
    }
    reverse(cost.begin(), cost.end());
    reverse(ind.begin(), ind.end());
    long long j = lower_bound(cost.begin(), cost.end(), p) - cost.begin();
    if (j == cost.size()) {
      cout << 1 << endl;
    } else if (cost[j] == p) {
      cout << ind[j] + 1 << endl;
    } else {
      if (j == 0) {
        cout << s.size() << endl;
      } else
        cout << ind[j - 1] + 1 << endl;
    }
  }
}
