#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;
    long long n = s.size();
    long long i = n - 2;
    if (p < min(a, b)) {
      cout << n << endl;
      continue;
    }
    while (i >= 0) {
      if (s[i] == 'A') {
        if (p < a) {
          p = -1;
          cout << i + 2 << endl;
          break;
        }
        p -= a;
        while (s[i] == 'A') {
          i--;
          if (i < 0) break;
        }
      }
      if (i < 0) break;
      if (s[i] == 'B') {
        if (p < b) {
          p = -1;
          cout << i + 2 << endl;
          break;
        }
        p -= b;
        while (s[i] == 'B') {
          i--;
          if (i < 0) break;
        }
      }
    }
    if (p >= 0) {
      cout << 1 << endl;
    }
  }
}
