#include <bits/stdc++.h>
using namespace std;
bool isprime(long long n) {
  if (n == 1) return false;
  if (n == 2) return true;
  for (long long i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}
long long poww(long long b, long long e) {
  if (e == 0)
    return 1;
  else if (e % 2 == 0) {
    long long a = pow(b, e / 2);
    return a * a;
  } else {
    long long a = pow(b, e / 2);
    return b * a * a;
  }
}
long long powm(long long x, long long y, long long m = 1000000007) {
  x = x % m;
  long long res = 1;
  while (y) {
    if (y & 1) res = res * x;
    res %= m;
    y = y >> 1;
    x = x * x;
    x %= m;
  }
  return res;
}
long long modInverse(long long a, long long m = 1000000007) {
  return powm(a, m - 2, m);
}
void print(vector<long long> v) {
  for (long long i = 0; i < v.size(); i++) {
    cout << v[i] << " ";
  }
}
void print(long long arr[]) {
  long long size = *(&arr + 1) - arr;
  for (long long i = 0; i < size; i++) {
    cout << arr[i] << " ";
  }
}
string to_bin(long long n) {
  string res = "";
  long long i = 0;
  while (n > 0) {
    if (n % 2 == 1) {
      res = res + '1';
    } else {
      res = res + '0';
    }
    n /= 2;
    i++;
  }
  reverse(res.begin(), res.end());
  return res;
}
long long to_dec(string second) {
  long long n = second.size(), ans = 0, temp = 1;
  for (long long i = n - 1; i >= 0; i--) {
    long long x = second[i] - '0';
    ans += x * temp;
    temp *= 2;
  }
  return ans;
}
void result(bool first) {
  if (first)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
void solve() {
  long long a, b, p;
  cin >> a >> b >> p;
  string second;
  cin >> second;
  reverse(second.begin(), second.end());
  long long n = second.length();
  long long ind = 1;
  long long maxi;
  for (long long i = 1; i < n; i++) {
    char ch = second[i];
    if (second[i] == 'B') {
      if (p >= b) {
        p -= b;
        if (i != n - 1) {
          while (second[i + 1] == 'B') {
            i++;
          }
        }
        ind = i + 1;
      } else
        break;
    } else if (second[i] == 'A') {
      if (p >= a) {
        p -= a;
        if (i != n - 1) {
          while (second[i + 1] == 'A') {
            i++;
          }
        }
        ind = i + 1;
      } else
        break;
    }
  }
  long long ans = n - ind + 1;
  cout << ans << endl;
}
int32_t main() {
  ios_base::sync_with_stdio();
  cin.tie(0);
  cout.tie(0);
  long long tests;
  cin >> tests;
  while (tests--) solve();
}
