#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long a, b, p;
    cin >> a >> b >> p;
    string s;
    cin >> s;
    vector<long long> cost(s.size() + 1, 0);
    long long cur = s.size() - 2, val = 0;
    while (cur >= 0) {
      if (s[cur] == 'A') {
        val += a;
        while (cur >= 0 && s[cur] == 'A') {
          cost[cur] = val;
          cur--;
        }
      } else if (s[cur] == 'B') {
        val += b;
        while (cur >= 0 && s[cur] == 'B') {
          cost[cur] = val;
          cur--;
        }
      }
    }
    for (long long i = (long long)(0); i <= (long long)(s.size() - 1); i++) {
      if (cost[i] <= p) {
        cout << i + 1 << '\n';
        break;
      }
    }
  }
}
