#include <bits/stdc++.h>
using namespace std;
const double PI = 3.141592653589793;
long long a[30];
long long b[30][30];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int a, b, p;
    cin >> a >> b >> p;
    string s;
    cin >> s;
    int j = s.size() - 1;
    int n = s.size();
    char cur = s[n - 2];
    int x = 1;
    if (cur == 'B') x = 2;
    for (int i = n - 2; i >= 0; i--) {
      if (s[i] == cur and x == 1 and cur == 'A') {
      } else if (s[i] == cur and x == 2 and cur == 'B') {
      } else {
        if (cur == 'A') {
          p -= a;
          if (p >= 0) j = i + 1;
          cur = 'B';
          x = 2;
        } else {
          cur = 'A';
          x = 1;
          p -= b;
          if (p >= 0) j = i + 1;
        }
      }
      if (p < 0) break;
    }
    if (cur == 'A') {
      p -= a;
      if (p >= 0) j = 0;
    } else {
      p -= b;
      if (p >= 0) j = 0;
    }
    cout << (j + 1) << endl;
  }
  return 0;
}
