#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int a, b, p;
    cin >> a >> b >> p;
    string s1;
    cin >> s1;
    int n = s1.size();
    map<char, int> mp;
    mp['A'] = a;
    mp['B'] = b;
    if (n == 2) {
      if (mp[s1[0]] > p) {
        cout << "2" << endl;
      } else {
        cout << "1" << endl;
      }
      continue;
    }
    vector<char> distinct;
    vector<int> index;
    distinct.push_back(s1[0]);
    index.push_back(0);
    char last = s1[0];
    for (int i = 1; i < n - 1; i++) {
      if (s1[i] != last) {
        distinct.push_back(s1[i]);
        index.push_back(i);
        last = s1[i];
      }
    }
    long long int sum = 0, ind = n - 1;
    for (int i = distinct.size() - 1; i >= 0; i--) {
      sum += mp[distinct[i]];
      if (sum <= p) {
        ind = index[i];
      }
    }
    cout << ind + 1 << endl;
  }
  return 0;
}
