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