#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int a, b, p;
    string s;
    cin >> a >> b >> p >> s;
    int l = s.size() - 2;
    if (p < a && p < b) {
      cout << s.size() << endl;
      continue;
    }
    while (l >= 0 && (p >= a || p >= b)) {
      if (s[l] == 'A' && p >= a && l >= 0) {
        while (s[l] == 'A') l--;
        p -= a;
      } else if (s[l] == 'B' && p >= b && l >= 0) {
        while (s[l] == 'B') l--;
        p -= b;
      } else
        break;
    }
    cout << l + 2 << endl;
  }
}
