After a long party Petya decided to return home, but he turned out to be at the opposite end of the town from his home. There are $n$ crossroads in the line in the town, and there is either the bus or the tram station at each crossroad.

The crossroads are represented as a string $s$ of length $n$, where $s_i = \texttt{A}$, if there is a bus station at $i$-th crossroad, and $s_i = \texttt{B}$, if there is a tram station at $i$-th crossroad. Currently Petya is at the first crossroad (which corresponds to $s_1$) and his goal is to get to the last crossroad (which corresponds to $s_n$).

If for two crossroads $i$ and $j$ for all crossroads $i, i+1, \ldots, j-1$ there is a bus station, one can pay $a$ roubles for the bus ticket, and go from $i$-th crossroad to the $j$-th crossroad by the bus (it is not necessary to have a bus station at the $j$-th crossroad). Formally, paying $a$ roubles Petya can go from $i$ to $j$ if $s_t = \texttt{A}$ for all $i \le t < j$. 

If for two crossroads $i$ and $j$ for all crossroads $i, i+1, \ldots, j-1$ there is a tram station, one can pay $b$ roubles for the tram ticket, and go from $i$-th crossroad to the $j$-th crossroad by the tram (it is not necessary to have a tram station at the $j$-th crossroad). Formally, paying $b$ roubles Petya can go from $i$ to $j$ if $s_t = \texttt{B}$ for all $i \le t < j$.

For example, if $s$="AABBBAB", $a=4$ and $b=3$ then Petya needs:[Image]  buy one bus ticket to get from $1$ to $3$,  buy one tram ticket to get from $3$ to $6$,  buy one bus ticket to get from $6$ to $7$. 

Thus, in total he needs to spend $4+3+4=11$ roubles. Please note that the type of the stop at the last crossroad (i.e. the character $s_n$) does not affect the final expense.

Now Petya is at the first crossroad, and he wants to get to the $n$-th crossroad. After the party he has left with $p$ roubles. He's decided to go to some station on foot, and then go to home using only public transport.

Help him to choose the closest crossroad $i$ to go on foot the first, so he has enough money to get from the $i$-th crossroad to the $n$-th, using only tram and bus tickets.


-----Input-----

Each test contains one or more test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$).

The first line of each test case consists of three integers $a, b, p$ ($1 \le a, b, p \le 10^5$) — the cost of bus ticket, the cost of tram ticket and the amount of money Petya has.

The second line of each test case consists of one string $s$, where $s_i = \texttt{A}$, if there is a bus station at $i$-th crossroad, and $s_i = \texttt{B}$, if there is a tram station at $i$-th crossroad ($2 \le |s| \le 10^5$).

It is guaranteed, that the sum of the length of strings $s$ by all test cases in one test doesn't exceed $10^5$.


-----Output-----

For each test case print one number — the minimal index $i$ of a crossroad Petya should go on foot. The rest of the path (i.e. from $i$ to $n$ he should use public transport).


-----Example-----
Input
5
2 2 1
BB
1 1 1
AB
3 2 8
AABBBBAABB
5 3 4
BBBBB
2 1 1
ABABAB

Output
2
1
3
1
6

Difficulty: EASY

Solutions:
for t in range(int(input())):
	(a, b, p) = map(int, input().split(' '))
	s = input()
	if s[-2] == 'B' and b > p or (s[-2] == 'A' and a > p):
		print(len(s))
	else:
		cur = s[-2]
		if s[-2] == 'B':
			cost = b
		if s[-2] == 'A':
			cost = a
		store = 0
		for i in range(len(s) - 3, -1, -1):
			if cur != s[i]:
				if s[i] == 'B':
					cur = 'B'
					cost += b
				if s[i] == 'A':
					cur = 'A'
					cost += a
			if cost > p:
				store = i + 2
				break
		if store == 0:
			print(1)
		else:
			print(store)


import sys
n = sys.stdin.buffer.readline()
for i in range(int(n)):
	(a, b, h) = map(int, input().split())
	f = 0
	s = input()
	s = list(s)
	n = len(s)
	j = n - 1
	sum_ = 0
	while j >= 0 and sum_ <= h:
		if s[j - 1] != s[j] or j == n - 1:
			if s[j - 1] == 'A':
				sum_ += a
			else:
				sum_ += b
		j -= 1
	print(j + 1 + 1)


n = int(input())
l1 = []
for i in range(n):
	d = {}
	l = []
	(a, b, c) = input().split()
	(a, b, c) = (int(a), int(b), int(c))
	c1 = c
	s = input()
	s = s[:len(s) - 1]
	z = len(s)
	k = ''
	p = 0
	for j in range(z):
		if s[j] != k:
			d[j] = s[j]
			k = s[j]
	for x in d:
		l.append(x)
	l = l[::-1]
	for p in l:
		if d[p] == 'A':
			if c1 - a >= 0:
				c1 = c1 - a
				z = p
			else:
				break
		elif c1 - b >= 0:
			c1 = c1 - b
			z = p
		else:
			break
	l1.append(z + 1)
for i in l1:
	print(i)


for _ in range(int(input())):
	(a, b, p) = map(int, input().split())
	price = {'A': a, 'B': b}
	stat = input()
	dp = [0] * len(stat)
	dp[-2] = price[stat[-2]]
	for i in range(len(stat) - 3, -1, -1):
		dp[i] = dp[i + 1]
		if stat[i] != stat[i + 1]:
			dp[i] += price[stat[i]]
	i = 0
	while dp[i] > p:
		i += 1
	print(i + 1)


import sys
input = sys.stdin.readline
for j in range(int(input())):
	(a, b, p) = list(map(int, input().split(' ')))
	s = input().rstrip()
	costs = [0 for x in range(len(s))]
	costs[len(s) - 1] = 0
	if s[len(s) - 2] == 'B':
		costs[len(s) - 2] = b
	else:
		costs[len(s) - 2] = a
	for it in range(3, len(s) + 1):
		if s[len(s) - it] != s[len(s) - it + 1]:
			costs[len(s) - it] = costs[len(s) - it + 1] + (s[len(s) - it] == 'A') * a + (s[len(s) - it] == 'B') * b
		else:
			costs[len(s) - it] = costs[len(s) - it + 1]
	for j in range(len(costs)):
		if costs[j] <= p:
			print(j + 1)
			break


t = int(input())
for tc in range(t):
	(a, b, p) = list(map(int, input().split()))
	s = input()
	result = len(s)
	for i in range(len(s) - 2, -1, -1):
		if i == 0 or s[i] != s[i - 1]:
			cost = a if s[i] == 'A' else b
			if cost > p:
				break
			else:
				p = p - cost
				result = i + 1
	print(result)


I = input
t = 'AB'
for _ in [0] * int(I()):
	(*a, p) = map(int, I().split())
	s = I()[:-1]
	s = chr(ord(s[0]) ^ 3) + s
	i = len(s) - 1
	j = t.find(s[-1])
	while i and p >= a[j]:
		p -= a[j]
		j ^= 1
		i = s.rfind(t[j], 0, i)
	print(i + 1)


def fa(arr):
	c = 0
	for i in arr:
		if i == 'B':
			break
		else:
			c += 1
	return c

def fb(arr):
	c = 0
	for i in arr:
		if i == 'A':
			break
		else:
			c += 1
	return c
for i in range(int(input())):
	(a, b, p) = map(int, input().split())
	s = input()
	arr = []
	i = 0
	ic = 0
	t = 0
	while i < len(s):
		if s[i] == 'A':
			x = fa(s[i:])
			arr.append((x, 'a'))
			i += x
			ic += a
			t += x
		else:
			x = fb(s[i:])
			arr.append((x, 'b'))
			i += x
			ic += b
			t += x
	if len(arr) > 1:
		if arr[-1][0] == 1:
			if arr[-1][1] == 'a':
				ic -= a
			else:
				ic -= b
	if ic > p:
		if len(arr) == 1:
			print(arr[0][0])
		else:
			i = 0
			t = 1
			while ic > p and i < len(arr):
				if arr[i][1] == 'a':
					ic -= a
					t += arr[i][0]
				else:
					ic -= b
					t += arr[i][0]
				i += 1
			if i == len(arr):
				print(t - 1)
			else:
				print(t)
	else:
		print(1)


for _ in range(int(input())):
	(a, b, p) = [int(i) for i in input().split()]
	s = input()
	n = len(s)
	c = a if s[n - 2] == 'A' else b
	if c > p:
		print(n)
	else:
		i = n - 3
		while i > -1:
			if s[i] != s[i + 1]:
				if s[i] == 'A':
					c += a
				else:
					c += b
				if c > p:
					print(i + 2)
					break
			i -= 1
		else:
			print(1)


for _ in range(int(input())):
	(a, b, p) = map(int, input().split())
	s = input()
	naw = 0
	for q in range(len(s) - 2, -1, -1):
		if (q == len(s) - 2 or s[q] != s[q + 1]) and naw + (a if s[q] == 'A' else b) > p:
			print(q + 2)
			break
		elif q == len(s) - 2 or s[q] != s[q + 1]:
			naw += a if s[q] == 'A' else b
	else:
		print(1)


t = int(input())
for _ in range(t):
	(a, b, p) = map(int, input().split())
	s = input()
	cs = {'A': a, 'B': b}
	c = 0
	i = len(s) - 1
	while i > 0 and c + cs[s[i - 1]] <= p:
		c += cs[s[i - 1]]
		i -= 1
		while i > 0 and s[i - 1] == s[i]:
			i -= 1
	print(i + 1)


from os import path
from sys import stdin, stdout
maxn = 200005
if path.exists('inp.txt'):
	stdin = open('inp.txt', 'r')
q = int(stdin.readline())
for _ in range(q):
	(a, b, p) = map(int, stdin.readline().split())
	inp = stdin.readline().split()
	s = inp[0]
	cp = 0
	check = 0
	last = len(s)
	s = s[:-1]
	if s[0] == 'A':
		s = 'B' + s
	else:
		s = 'A' + s
	cur = s[-1]
	for i in range(len(s) - 1, -1, -1):
		if cur == 'A' and s[i] == 'B':
			if cp + a <= p:
				cp += a
				cur = 'B'
				last = i + 1
			else:
				break
		if cur == 'B' and s[i] == 'A':
			if cp + b <= p:
				cp += b
				cur = 'A'
				last = i + 1
			else:
				break
	print(last)


t = int(input())
for _ in range(t):
	(a, b, p) = list(map(int, input().split()))
	s = input()
	price = {'A': a, 'B': b}
	fund = 0
	indx = len(s) - 2
	if not (indx >= 0 and fund + price[s[indx]] <= p):
		print(len(s))
		continue
	curr_trans = s[indx]
	last_indx = indx + 1
	indx -= 1
	while indx >= 0 and fund + price[s[indx]] <= p:
		while indx >= 0 and s[indx] == curr_trans:
			last_indx = indx + 1
			indx -= 1
		fund += price[s[indx + 1]]
		curr_trans = s[indx]
	print(last_indx)


t = int(input())
for i in range(t):
	ans = False
	(a, b, p) = map(int, input().split())
	s = input()
	dp = [0] * (len(s) + 1)
	s = s[:-1] + 'C'
	for j in range(len(s) - 2, -1, -1):
		if s[j + 1] == s[j]:
			dp[j] = dp[j + 1]
		elif s[j] == 'A':
			dp[j] = dp[j + 1] + a
		else:
			dp[j] = dp[j + 1] + b
		if dp[j] > p:
			ans = True
			print(j + 2)
			break
	if not ans:
		print(1)


n = int(input())
for i in range(n):
	(a, b, p) = map(int, input().split())
	s = input()[::-1]
	cost = 0
	p1 = s[0]
	if s[0] == s[1]:
		if s[0] == 'A':
			cost += a
		else:
			cost += b
	for j in range(1, len(s), 1):
		if p1 != s[j]:
			p1 = s[j]
			if p1 == 'A':
				cost += a
			else:
				cost += b
		if cost > p:
			if j != 0:
				print(len(s) - (j - 1))
			else:
				print(len(s))
			break
	else:
		print(1)


def check(s, a, b, mid, p):
	dc = {'A': a, 'B': b}
	cr = dc[s[mid]]
	cur = s[mid]
	for i in range(mid + 1, len(s) - 1):
		if s[i] != cur:
			cur = s[i]
			cr += dc[cur]
	if cr <= p:
		return True
	else:
		return False

def f(s, a, b, p):
	lo = 0
	hi = len(s) - 1
	res = len(s)
	while lo <= hi:
		mid = (lo + hi) // 2
		if check(s, a, b, mid, p):
			hi = mid - 1
			res = min(mid + 1, res)
		else:
			lo = mid + 1
	return res
for i in range(int(input())):
	(a, b, p) = map(int, input().strip().split())
	s = input()
	print(f(s, a, b, p))


import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.readline())

def MI():
	return map(int, sys.stdin.readline().split())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline()[:-1]

def main():
	t = II()
	for _ in range(t):
		(a, b, p) = MI()
		s = SI()[:-1] + '@'
		n = len(s)
		for i in range(n - 1, -1, -1):
			if i > 0 and s[i] != s[i - 1]:
				toll = a if s[i - 1] == 'A' else b
				if toll <= p:
					p -= toll
				else:
					break
		print(i + 1)
main()


from sys import stdin, gettrace
if not gettrace():

	def input():
		return next(stdin)[:-1]

def main():

	def solve():
		(a, b, p) = map(int, input().split())
		ss = input()
		cost = 0
		last = 'X'
		for (i, s) in enumerate(ss[-2::-1]):
			if s != last:
				if s == 'A':
					cost += a
				else:
					cost += b
				last = s
				if cost > p:
					break
		else:
			print(1)
			return
		print(len(ss) - i)
	q = int(input())
	for _ in range(q):
		solve()
main()


from sys import stdin, stdout
nmbr = lambda : int(input())
lst = lambda : list(map(int, input().split()))
for _ in range(nmbr()):
	(a, b, cc) = lst()
	s = input()
	n = len(s)
	dp = [0] * n
	dp[n - 2] = b if s[n - 2] == 'B' else a
	for i in range(n - 3, -1, -1):
		dp[i] = dp[i + 1]
		if s[i] != s[i + 1]:
			if s[i] == 'A':
				dp[i] += a
			else:
				dp[i] += b
	ans = n
	for i in range(n):
		if dp[i] <= cc:
			ans = i + 1
			break
	print(ans)


testcases = int(input())
for j in range(testcases):
	(a, b, p) = map(int, input().split())
	spent = 0
	cross = input()
	pref = []
	inds = []
	startval = 0
	endval = 0
	for s in range(1, len(cross)):
		if cross[s] == cross[s - 1]:
			endval = s
		else:
			spent = 0
			if cross[startval] == 'A':
				spent += a
			else:
				spent += b
			pref.append(spent)
			inds.append((startval, endval))
			startval = s
			endval = s
	if len(inds) == 0:
		spent = 0
		if cross[startval] == 'A':
			spent += a
		else:
			spent += b
		pref.append(spent)
		inds.append((startval, endval))
	elif inds[-1][1] != len(cross) - 1:
		spent = 0
		if cross[startval] == 'A':
			spent += a
		else:
			spent += b
		pref.append(spent)
		inds.append((startval, endval))
	outy = []
	total = sum(pref)
	if inds[-1][0] == inds[-1][1] == len(cross) - 1:
		total -= pref[-1]
	for s in range(len(inds)):
		if p < total:
			outy.append(inds[s][1])
			total -= pref[s]
		else:
			outy.append(inds[s][0])
			break
	if len(outy) == 0:
		print(len(cross))
	else:
		print(outy[-1] + 1)


for t in range(int(input())):
	(a, b, p) = map(int, input().split())
	s = input()
	c = b if s[-2] == 'B' else a
	if c > p:
		print(len(s))
		continue
	for i in range(len(s) - 3, -1, -1):
		if s[i] == s[i + 1]:
			continue
		c += b if s[i] == 'B' else a
		if c > p:
			print(i + 2)
			break
	else:
		print(1)


get_int = lambda : int(input())
get_mul_int = lambda : map(int, input().rstrip().split())
get_list = lambda : list(map(int, input().rstrip().split()))
TEST_CASES = True

def main():
	(a, b, p) = get_mul_int()
	s = input()
	n = len(s)
	if s == 'A' * n:
		if p >= a:
			print(1)
		else:
			print(n)
		return
	elif s == 'B' * n:
		if p >= b:
			print(1)
		else:
			print(n)
		return
	if n == 2:
		if s[0] == 'A':
			if p - a >= 0:
				print(1)
			else:
				print(2)
		elif p - b >= 0:
			print(1)
		else:
			print(2)
		return
	if s[-2] == 'B':
		if p - b >= 0:
			p -= b
		else:
			print(n)
			return
	elif p - a >= 0:
		p -= a
	else:
		print(n)
		return
	i = n - 2
	while i > 0:
		if s[i] != s[i - 1]:
			if s[i - 1] == 'B':
				if p - b >= 0:
					p -= b
				else:
					break
			elif p - a >= 0:
				p -= a
			else:
				break
			i -= 1
		else:
			i -= 1
	print(i + 1)
if not TEST_CASES:
	main()
else:
	[main() for _ in range(int(input()))]


from sys import stdin
input = stdin.readline
t = int(input())
for _ in range(t):
	(a, b, p) = map(int, input().split())
	s = [ord(x) - ord('A') for x in input().rstrip()]
	l = len(s)
	k = [a, b]
	m = [0, 0]
	currChar = s[l - 2]
	while p >= k[currChar]:
		p -= k[currChar]
		m[currChar] += 1
		currChar = (currChar + 1) % 2
	m = sum(m)
	currChar = s[l - 2]
	if m == 0:
		print(l)
	else:
		for i in range(l - 2, -1, -1):
			if currChar == s[i]:
				if i == 0:
					currIndex = 1
					break
				continue
			else:
				m -= 1
				if m <= 0:
					currIndex = i + 2
					break
				elif i == 0:
					currIndex = 1
					break
				currChar = s[i]
		print(currIndex)


t = int(input())
for _ in range(t):
	(a, b, p) = list(map(int, input().split()))
	s = input()
	c = 0
	if s[len(s) - 2] == 'A':
		c = a
	else:
		c = b
	i = len(s) - 2
	if c > p:
		print(len(s))
		continue
	if i == 0:
		print(i + 1)
		continue
	i = len(s) - 3
	while i >= 0:
		if s[i] != s[i + 1]:
			if s[i] == 'A':
				c = c + a
			else:
				c = c + b
		if c > p:
			break
		i = i - 1
	i = i + 1
	print(i + 1)


for i in range(int(input())):
	(a, b, p) = map(int, input().split())
	s = input()
	dp = [0 for i in range(len(s))]
	for j in range(len(s) - 2, -1, -1):
		if s[j] != s[j + 1] or dp[j + 1] == 0:
			if s[j] == 'B':
				if dp[j + 1] == 0:
					dp[j] = b
				else:
					dp[j] = dp[j + 1] + b
			elif dp[j + 1] == 0:
				dp[j] = a
			else:
				dp[j] = dp[j + 1] + a
		else:
			dp[j] = dp[j + 1]
	ans = 1
	for i in dp:
		if i > p:
			ans += 1
		else:
			break
	print(ans)


t = int(input())
for kikoriki in range(t):
	(a, b, p) = map(int, input().split())
	s = input()
	left = -1
	right = len(s) - 1
	while left + 1 != right:
		mid = (left + right) // 2
		tp = s[mid]
		k = mid
		c = 0
		while k < len(s) - 1:
			if tp == 'A':
				c += a
			else:
				c += b
			while tp == s[k]:
				k += 1
				if k == len(s) - 1:
					break
			if tp == 'A':
				tp = 'B'
			else:
				tp = 'A'
		if c <= p:
			right = mid
		else:
			left = mid
	print(right + 1)


from sys import stdin
r = stdin.readline

def solve(A, p):
	(ans, ins) = (len(A), False)
	for i in range(len(A) - 1, -1, -1):
		if A[i] > p:
			ans = i + 2
			ins = True
			break
	if not ins:
		ans = 1
	return ans

def main():
	cases = int(r())
	for case in range(cases):
		(a, b, p) = map(int, r().strip().split())
		cost = {'A': a, 'B': b}
		line = r().strip()
		n = len(line)
		(A, i, s, val) = ([0 for _ in range(n)], n - 2, line[n - 1], 0)
		while i >= 0:
			A[i] = A[i + 1] + cost[line[i]]
			j = i - 1
			while j >= 0 and line[j] == line[i]:
				A[j] = A[i]
				j -= 1
			i = j
		print(solve(A, p))
main()


import sys
import math
import heapq
import collections
fast_reader = sys.stdin.readline
fast_writer = sys.stdout.write

def input():
	return fast_reader().strip()

def print(*argv):
	fast_writer(' '.join((str(i) for i in argv)))
	fast_writer('\n')

def printspace(*argv):
	fast_writer(' '.join((str(i) for i in argv)))
	fast_writer(' ')

def inputnum():
	return int(input())

def inputnums():
	return map(int, input().split())

def inputlist():
	return list(map(int, input().split()))

def inputstring():
	return [x for x in input()]

def inputstringnum():
	return [ord(x) - ord('a') for x in input()]

def inputmatrixchar(rows):
	arr2d = [[j for j in input().strip()] for i in range(rows)]
	return arr2d

def inputmatrixint(rows):
	arr2d = []
	for _ in range(rows):
		arr2d.append([int(i) for i in input().split()])
	return arr2d
t = int(input())
for q in range(t):
	(a, b, p) = inputnums()
	s1 = inputstring()
	s = ['Z'] + s1
	l = len(s)
	cur = 0
	for i in reversed(range(l - 1)):
		if s[i] != s[i - 1]:
			if s[i] == 'B':
				cur += b
				if cur > p:
					break
				else:
					l = i + 1
			else:
				cur += a
				if cur > p:
					break
				else:
					l = i + 1
	print(l - (l != 1))


for _ in ' ' * int(input()):
	(a, b, c) = map(int, input().split())
	d = input()
	e = 'p'
	for i in range(len(d) - 2, -2, -1):
		if e != d[i]:
			c -= a if d[i] == 'A' else b
			e = d[i]
			if c < 0:
				break
	print(i + 2)


t = int(input())
res = [0] * t
for i in range(t):
	params = [int(item) for item in input().split(' ')]
	a = params[0]
	b = params[1]
	p = params[2]
	stops = list(input())
	n = len(stops)
	cost = [0] * n
	if stops[-2] == 'A':
		cost[-2] = a
	else:
		cost[-2] = b
	for j in reversed(range(1, n - 1)):
		if stops[j - 1] == 'A' and stops[j] == 'B':
			cost[j - 1] = cost[j] + a
		elif stops[j - 1] == 'B' and stops[j] == 'A':
			cost[j - 1] = cost[j] + b
		else:
			cost[j - 1] = cost[j]
	ans = 0
	for j in range(n):
		if cost[j] <= p:
			ans = j
			break
	print(ans + 1)


t = int(input())
while t > 0:
	(a, b, p) = map(int, input().split())
	bus = input()
	l = len(bus)
	cost = 0
	flag = 0
	if l == 2:
		if bus[0] == 'A':
			if p >= a:
				print('1')
			else:
				print('2')
		elif p >= b:
			print('1')
		else:
			print('2')
	else:
		if bus[l - 2] == 'B':
			cost += b
		else:
			cost += a
		if p < cost:
			print(l)
		else:
			for j in range(l - 3, -1, -1):
				if bus[j] == bus[j + 1]:
					continue
				elif bus[j] == 'B':
					cost += b
				else:
					cost += a
				if cost > p:
					flag = 1
					break
			if flag == 0 and j == 0:
				print('1')
			else:
				ans = j + 2
				print(ans)
	t -= 1


for test in range(int(input())):
	(a, b, p) = map(int, input().strip().split(' '))
	s = input()
	i = len(s) - 2
	if len(s) == 2:
		if s[0] == 'A':
			p -= a
			if p >= 0:
				print(1)
			else:
				print(2)
		else:
			p -= b
			if p >= 0:
				print(1)
			else:
				print(2)
	elif s[i] == 'A':
		p -= a
		flag = 0
		current = 0
		while i >= 0:
			if s[i] == 'A':
				if current == 0:
					pass
				else:
					p -= a
					current = 0
			if s[i] == 'B':
				if current == 1:
					pass
				else:
					p -= b
					current = 1
			if p < 0:
				print(i + 2)
				flag = 1
				break
			i -= 1
		if flag == 0:
			if i == -1:
				print(1)
			else:
				print(i + 1)
	else:
		p -= b
		current = 1
		flag = 0
		while i >= 0:
			if s[i] == 'A':
				if current == 0:
					pass
				else:
					p -= a
					current = 0
			if s[i] == 'B':
				if current == 1:
					pass
				else:
					p -= b
					current = 1
			if p < 0:
				print(i + 2)
				flag = 1
				break
			i -= 1
		if flag == 0:
			if i == -1:
				print(1)
			else:
				print(i + 1)


from sys import exit

def i():
	return input()

def ii():
	return int(input())

def iis():
	return map(int, input().split())

def liis():
	return list(map(int, input().split()))

def print_array(a):
	print(' '.join(map(str, a)))
t = ii()
for _ in range(t):
	(a, b, p) = iis()
	s = input()
	s = s[:-1]
	if not len(s):
		print(1)
		continue
	last = s[0]
	count = 0
	if last == 'A':
		count += a
	else:
		count += b
	for c in s:
		if c == last:
			continue
		if c == 'A':
			count += a
		else:
			count += b
		last = c
	i = 0
	first = count
	while count > p and i < len(s):
		if i != 0 and s[i] == last:
			i += 1
			continue
		last = s[i]
		if last == 'A':
			count -= a
		else:
			count -= b
		i += 1
	if first == count:
		print(i + 1)
	else:
		while i > 0 and i < len(s) and (s[i] == s[i - 1]):
			i += 1
		print(i + 1)


def minimum_index(a, b, p, s):
	expense = 0
	j = len(s) - 2
	while j >= 0:
		i = j
		while i > 0 and s[i] == s[i - 1]:
			i -= 1
		delta = a if s[j] == 'A' else b
		if expense + delta > p:
			return j + 2
		expense += delta
		j = i - 1
	return 1
T = int(input())
for t in range(T):
	(a, b, p) = list(map(int, input().split()))
	s = input()
	print(minimum_index(a, b, p, s))


for _ in ' ' * int(input()):
	(a, b, c) = map(int, input().split())
	o = input()
	z = o.replace('AB', 'A B').replace('BA', 'B A').split()
	s = 0
	k = len(z)
	if 'A' in z[0]:
		s = a * ((k + 1) // 2) + b * (k // 2)
	else:
		s = b * ((k + 1) // 2) + a * (k // 2)
	i = 0
	p = 0
	if len(z[-1]) == 1:
		s -= [a, b]['B' == z[-1]]
		z.pop()
	for i in range(len(z)):
		if s <= c:
			break
		else:
			p += len(z[i])
			s -= [a, b]['B' == z[i][0]]
	print(min(1 + p, len(o)))


def home(l, a, b, p):
	c = ''
	d = 0
	x = 0
	for i in range(len(l) - 2, -1, -1):
		if c != l[i]:
			c = l[i]
			if c == 'A':
				p = p - a
				d = i
			else:
				p = p - b
				d = i
			if p < 0:
				x = 1
				break
	if x == 0:
		print(1)
	else:
		print(d + 2)
	return
n = int(input())
for i in range(n):
	t = input()
	l = list(map(int, t.split(' ')))
	s = input()
	l1 = list(s)
	home(l1, l[0], l[1], l[2])


import sys
input = sys.stdin.readline
(t,) = map(int, input().split())
for _ in range(t):
	(a, b, C) = map(int, input().split())
	d = {'A': a, 'B': b}
	s = input().strip()
	ss = len(s)
	bb = None
	for i in range(ss - 2, -1, -1):
		if s[i] == bb:
			continue
		C -= d[s[i]]
		if C < 0:
			print(i + 2)
			break
		bb = s[i]
	else:
		print(1)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(a, b, p) = map(int, input().split())
	s = input()[:-1]
	l = [(0, s[0])]
	for i in range(1, len(s) - 1):
		if s[i] != s[i - 1]:
			l.append((i, s[i]))
	cost = 0
	ans = len(s)
	for (i, si) in l[::-1]:
		if si == 'A':
			cost += a
		else:
			cost += b
		if cost <= p:
			ans = i + 1
	print(ans)


import os
from io import BytesIO, IOBase
import sys
from collections import defaultdict, deque, Counter
from bisect import *
from math import sqrt, pi
import math
from itertools import permutations
from copy import deepcopy

def main():
	for _ in range(int(input())):
		(a, b, p) = map(int, input().split())
		s = input().rstrip()
		n = len(s)
		r = []
		c = []
		i = 0
		while i < n - 1:
			j = i
			while j < n - 1 and s[j] == s[j + 1]:
				j += 1
			r.append(j + 1)
			c.append((0 if i == 0 else c[-1]) + (a if s[i] == 'A' else b))
			i = j + 1
		ans = n
		m = len(c)
		for i in range(m):
			if c[-1] - (0 if i == 0 else c[i - 1]) <= p:
				ans = 1 if i == 0 else r[i - 1] + 1
				break
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


for _ in range(int(input())):
	(a, b, p) = map(int, input().split())
	lst = list(input())
	l = len(lst) - 2
	if lst[l] == 'A':
		if a > p:
			print(l + 2)
			continue
	elif b > p:
		print(l + 2)
		continue
	temp = lst[l]
	if temp == 'A':
		p -= a
	else:
		p -= b
	l -= 1
	while l >= 0:
		if lst[l] != temp:
			temp = lst[l]
			if temp == 'A':
				if a > p:
					break
				else:
					p -= a
			elif b > p:
				break
			else:
				p -= b
		l -= 1
	print(l + 2)


for _ in range(int(input())):
	(a, b, p) = map(int, input().split())
	s = input()
	n = len(s)
	dp = [-1 for _ in range(n)]
	for i in reversed(range(1, n)):
		if s[i - 1] == 'A':
			dp[i] = 0
		elif s[i - 1] == 'B':
			dp[i] = 1
	station = n
	for i in reversed(range(n)):
		if i == 0:
			station = 1
			break
		if i == n - 1:
			if dp[i] == 0:
				cost = a
			elif dp[i] == 1:
				cost = b
		elif dp[i] != dp[i + 1]:
			if dp[i] == 0:
				cost += a
			elif dp[i] == 1:
				cost += b
		if cost > p:
			station = i + 1
			break
	print(station)


for _ in range(int(input())):
	(a, b, p) = map(int, input().split())
	s = input()
	n = len(s)
	dp = [0] * n
	if s[-2] == 'A':
		dp[-2] = a
	else:
		dp[-2] = b
	for i in range(n - 3, -1, -1):
		if s[i] == s[i + 1]:
			dp[i] = dp[i + 1]
		elif s[i] == 'A':
			dp[i] = dp[i + 1] + a
		else:
			dp[i] = dp[i + 1] + b
	i = 0
	while dp[i] > p:
		i += 1
	print(i + 1)


import sys
input = sys.stdin.readline
LI = lambda : list(map(int, input().split()))
MI = lambda : map(int, input().split())
SI = lambda : input().strip('\n')
for _ in range(int(input())):
	(a, b, p) = MI()
	ss = SI()
	s = []
	num = [0] * len(ss)
	for (i, c) in enumerate(ss):
		if not s or s[-1][1] != c:
			s.append((i, c))
	ind = len(s) - 1 if ss[-1] == ss[-2] else len(s) - 2
	val = a if ss[-2] == 'A' else b
	for i in range(len(ss) - 2, -1, -1):
		if i < s[ind][0]:
			ind -= 1
			val += a if s[ind][1] == 'A' else b
		num[i] = val
	for (i, v) in enumerate(num):
		if v <= p:
			break
	print(i + 1)


from math import *

def binarySearch(arr, x, i):
	l = i
	r = len(arr) - 1
	while l <= r:
		mid = (l + r) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] < x:
			l = mid + 1
		else:
			r = mid - 1
	return -1

def js(arr, x):
	l = 0
	r = len(arr) - 1
	ans = -1
	while l <= r:
		m = (l + r) // 2
		if arr[m] <= x:
			ans = m
			l = m + 1
		else:
			r = m - 1
	return ans

def jg(arr, x):
	l = 0
	r = len(arr) - 1
	ans = -1
	while l <= r:
		m = (l + r) // 2
		if arr[m] >= x:
			ans = m
			r = m - 1
		else:
			l = m + 1
	return ans

def ceil(a, b):
	if a % b == 0:
		return int(a / b)
	else:
		return a // b + 1

def c(s, i, a, b):
	count = 0
	for j in range(i, len(s)):
		if s[i] != s[j]:
			if s[i] == 'A':
				count += a
			else:
				count += b
			i = j
	if i < len(s) - 1:
		if s[i] == 'A':
			count += a
		else:
			count += b
	return count
for i in range(int(input())):
	(a, b, p) = map(int, input().split())
	s = input()
	ans = 0
	l = 0
	r = len(s) - 1
	while l <= r:
		m = (l + r) // 2
		if c(s, m, a, b) <= p:
			ans = m
			r = m - 1
		else:
			l = m + 1
			if c(s, m + 1, a, b) <= p:
				ans = m + 1
	print(ans + 1)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
mod = 998244353
INF = float('inf')
from math import factorial
from collections import Counter, defaultdict, deque
from heapq import heapify, heappop, heappush

def main():
	for _ in range(N()):
		(a, b, p) = RL()
		s = list(input())
		le = len(s)
		dp = [INF] * le
		dp[-1] = 0
		cos = {'A': a, 'B': b}
		ind = le - 2
		for i in range(le - 2, -1, -1):
			if s[i] == s[i + 1]:
				dp[i] = cos[s[i]]
				ind = i - 1
			else:
				break
		pre = -1
		res = le
		for i in range(ind, -1, -1):
			if s[i] != s[i + 1]:
				dp[i] = dp[i + 1] + cos[s[i]]
			else:
				dp[i] = dp[i + 1]
		for i in range(le):
			if dp[i] <= p:
				res = min(res, i + 1)
				break
		print(res)
main()


for t in range(int(input())):
	(a, b, p) = map(int, input().split())
	s = input()
	n = len(s)
	c = [0] * n
	for i in range(n - 2, -1, -1):
		if s[i] != s[i + 1]:
			c[i] = a if s[i] == 'A' else b
	if s[-1] == s[-2]:
		c[-2] = a if s[-2] == 'A' else b
	for i in range(n - 2, -1, -1):
		c[i] += c[i + 1]
	res = n
	for i in range(n):
		if c[i] <= p:
			res = i + 1
			break
	print(res)


import sys
input = sys.stdin.readline
t = int(input())
for tests in range(t):
	(a, b, p) = map(int, input().split())
	S = list(input().strip())
	S[-1] = 'Z'
	now = 0
	for i in range(len(S) - 2, -1, -1):
		if S[i] == S[i + 1]:
			continue
		if S[i] == 'A':
			now += a
		elif S[i] == 'B':
			now += b
		if now > p:
			print(i + 2)
			break
	else:
		print(1)


def main():
	dct = dict()
	(a, b, p) = map(int, input().split())
	dct['A'] = a
	dct['B'] = b
	lst = input()
	last = lst[len(lst) - 2]
	have_to_pay = 0
	pre_last = len(lst)
	pos = 1
	for i in range(len(lst) - 2, -1, -1):
		if lst[i] != last:
			if have_to_pay + dct[last] > p:
				pos = i + 1
				break
			else:
				have_to_pay += dct[last]
				last = lst[i]
				pre_last = i + 2
	if have_to_pay + dct[last] > p:
		print(pre_last)
	else:
		print(pos)
t = int(input())
for i in range(t):
	main()


for _ in range(int(input())):
	(a, b, p) = map(int, input().split())
	s = input()[:-1] + 'c'
	n = len(s)
	d = {'A': a, 'B': b}
	for i in range(n - 1, -1, -1):
		if i > 0 and s[i] != s[i - 1]:
			x = d[s[i - 1]]
			if x <= p:
				p -= x
			else:
				break
	print(i + 1)


for i in range(int(input())):
	(a, b, c) = map(int, input().split())
	lst = list(map(str, input()))
	(m, n, f, r, l, s) = (0, 0, 0, 0, [], [])
	lst = lst[::-1]
	for (i, j) in enumerate(range(len(lst) - 1), start=1):
		f = i
		if lst[i] == 'A' and m == 0:
			if c >= a:
				c = c - a
				n = 0
				m = 1
			else:
				f = i - 1
				break
		elif lst[i] == 'B' and n == 0:
			if c >= b:
				c = c - b
				m = 0
				n = 1
			else:
				f = i - 1
				break
	r = len(lst) - f
	print(r)


from bisect import *
from collections import *
from itertools import *
import functools
import sys
import math
from decimal import *
from copy import *
from heapq import *
from fractions import *
getcontext().prec = 30
MAX = sys.maxsize
MAXN = int(1500000.0)
MOD = 10 ** 9 + 7
spf = [i for i in range(MAXN)]
spf[0] = spf[1] = -1

def sieve():
	for i in range(2, MAXN, 2):
		spf[i] = 2
	for i in range(3, int(MAXN ** 0.5) + 1):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def fib(n, m):
	if n == 0:
		return [0, 1]
	else:
		(a, b) = fib(n // 2)
		c = a % m * (b % m * 2 - a % m) % m
		d = a % m * (a % m) % m + b % m * b % m % m
		if n % 2 == 0:
			return [c, d]
		else:
			return [d, c + d]

def charIN(x=' '):
	return sys.stdin.readline().strip().split(x)

def arrIN(x=' '):
	return list(map(int, sys.stdin.readline().strip().split(x)))

def ncr(n, r):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % MOD
		den = den * (i + 1) % MOD
	return num * pow(den, MOD - 2, MOD) % MOD

def flush():
	return sys.stdout.flush()
for _ in range(int(input())):
	(a, b, p) = arrIN()
	s = input()
	n = len(s)
	prev = s[0]
	cost = 0
	for i in range(1, n):
		if prev != s[i]:
			cost += a if prev == 'A' else b
			prev = s[i]
	if s[-1] == s[-2]:
		cost += a if prev == 'A' else b
	if cost <= p:
		print(1)
	else:
		prev = s[0]
		for i in range(1, n):
			if prev != s[i]:
				cost -= a if prev == 'A' else b
				prev = s[i]
				if cost <= p:
					print(i + 1)
					break
		else:
			print(n)


t = int(input())
for x in range(t):
	(a, b, p) = input().split()
	a = int(a)
	b = int(b)
	p = int(p)
	s = input()
	l = [0]
	z = 0
	maxv = -1
	for i in range(len(s) - 2, -1, -1):
		l.append(0)
	for i in range(len(s) - 2, -1, -1):
		if i != len(s) - 2 and s[i] == s[i + 1]:
			z = l[i + 1]
		else:
			if s[i] == 'A':
				z = l[i + 1] + a
			if s[i] == 'B':
				z = l[i + 1] + b
		l[i] = z
		if l[i] <= p and l[maxv] <= l[i]:
			maxv = i
	if maxv != -1:
		print(maxv + 1)
	else:
		print(len(s))


t = int(input())
for _ in range(t):
	(a, b, p) = map(int, input().split())
	s = input()
	n = len(s)
	costs = []
	start = 0
	for i in range(n - 1):
		if s[i] != s[i + 1]:
			if s[i] == 'A':
				costs += [[a, i]]
			else:
				costs += [[b, i]]
	if s[-1] == s[-2]:
		ind = -1
		while ind > -n and s[ind - 1] == s[ind]:
			ind -= 1
		ind += n
		if s[-1] == 'A':
			costs += [[a, ind]]
		else:
			costs += [[b, ind]]
	pfx = [0] * len(costs)
	lol = [0] * n
	su = 0
	for i in range(len(costs) - 1, -1, -1):
		su += costs[i][0]
		pfx[i] = su
	start = 0
	for i in range(len(costs)):
		for j in range(start, costs[i][1] + 1):
			lol[j] = pfx[i]
		start = costs[i][1] + 1
	for j in range(start, n - 1):
		lol[j] = pfx[-1]
	lol[-1] = 0
	for i in range(n):
		if lol[i] <= p:
			ans = i
			break
	print(ans + 1)


from collections import deque
for _ in range(int(input())):
	(a, b, p) = map(int, input().split())
	s = input()
	cost = []
	c = 0
	i = 0
	while i < len(s) - 1:
		if s[i] == 'A':
			c += a
		else:
			c += b
		cost.append(c)
		j = i + 1
		while j < len(s) - 1 and s[j] == s[i]:
			cost.append(c)
			j += 1
		i = j
	last = cost[-1]
	ans = len(s)
	for i in range(len(s) - 1):
		if last - cost[i] + (a if s[i] == 'A' else b) <= p:
			ans = i + 1
			break
	print(ans)


t = int(input())
ans = []
for i in range(t):
	(a, b, p) = list(map(int, input().split(' ')))
	s = list(input())
	s.reverse()
	n = len(s)
	s_help = [0] * n
	s_help[0] = -1
	if s[1] == 'A':
		s_help[1] = a
	else:
		s_help[1] = b
	flag = 0
	if s_help[1] <= p:
		for i in range(2, n):
			if s[i] == s[i - 1]:
				s_help[i] = s_help[i - 1]
			elif s[i] == 'A':
				s_help[i] = s_help[i - 1] + a
			else:
				s_help[i] = s_help[i - 1] + b
			if s_help[i] > p:
				flag = 1
				ans.append(n - i + 1)
				break
		if flag == 0:
			ans.append(1)
	else:
		ans.append(n)
for i in range(0, t):
	print(ans[i])


for _ in range(int(input())):
	(a, b, p) = list(map(int, input().split()))
	s = input()
	ind = len(s)
	sum_ = 0
	while sum_ <= p and ind > 0:
		ind -= 1
		if ind == len(s) - 1 or s[ind - 1] != s[ind]:
			if s[ind - 1] == 'A':
				sum_ += a
			else:
				sum_ += b
	print(ind + 1)


for _ in range(int(input())):
	(a, b, p) = map(int, input().split())
	s = input()[::-1]
	where_to_go = len(s)
	paid = 0
	for (ind, sym) in enumerate(s):
		if ind != 0:
			if s[ind - 1] == sym:
				if paid == 0:
					p -= a if sym == 'A' else b
					if p < 0:
						break
					else:
						where_to_go -= 1
						paid = 1
				else:
					where_to_go -= 1
			else:
				p -= a if sym == 'A' else b
				if p < 0:
					break
				else:
					where_to_go -= 1
					paid = 1
		else:
			continue
	print(where_to_go)


def crossroad(a, b, p, string):
	current_price = 0
	ans = len(string)
	for i in range(len(string) - 1, 0, -1):
		if i == 1 or string[i - 1] != string[i - 2]:
			if string[i - 1] == 'A':
				current_price += a
			else:
				current_price += b
			if current_price > p:
				return ans
			else:
				ans = i
	return 1
t = int(input())
for j in range(t):
	(a_t, b_t, p_t) = map(int, input().split())
	string_t = input()
	print(crossroad(a_t, b_t, p_t, string_t))


import atexit
import io
import sys
import math
from collections import defaultdict, Counter
t = int(input())
for i in range(t):
	(a, b, p) = map(int, input().split())
	s = input()
	prev = ''
	ind = 0
	for j in range(len(s) - 2, -1, -1):
		if s[j] != prev or prev == '':
			if s[j] == 'A':
				p -= a
			else:
				p -= b
			prev = s[j]
			if p < 0:
				ind = j + 1
				break
	print(ind + 1)


for _ in range(int(input())):
	(a, b, p) = list(map(int, input().split()))
	ar = list(input())
	i = len(ar) - 2
	now = ar[i]
	flag = 0
	if now == 'A':
		if p >= a:
			flag = 1
	elif p >= b:
		flag = 1
	while i >= 0 and p > 0 and (flag == 1):
		if ar[i] == now:
			i -= 1
		else:
			if ar[i + 1] == 'A':
				p -= a
			else:
				p -= b
			if ar[i] == 'A':
				if p < a:
					break
				now = 'A'
			else:
				if p < b:
					break
				now = 'B'
	print(i + 2)


T = int(input())
for ti in range(T):
	(a, b, p) = map(int, input().split())
	sttion = input()
	LEN = len(sttion)
	station = LEN
	total = 0
	prev = ''
	for j in range(LEN - 1, 0, -1):
		if prev != sttion[j - 1]:
			if sttion[j - 1] == 'A':
				total += a
			else:
				total += b
		if total > p:
			station = j + 1
			break
		prev = sttion[j - 1]
	if total > p:
		print(station)
	else:
		print(1)


t = int(input())
for test in range(t):
	(a, b, money) = [int(i) for i in input().split()]
	route = input().strip()
	lastwas = None
	for (i, stop) in enumerate(route[-2::-1]):
		if not lastwas:
			lastwas = stop
		elif stop == lastwas:
			continue
		lastwas = stop
		if stop == 'A':
			money -= a
		else:
			money -= b
		if money < 0:
			break
	else:
		i += 1
	print(len(route) - i)


t = int(input())
while t:
	t -= 1
	(a, b, p) = map(int, input().split())
	s = input()
	n = len(s)
	s += '#'
	re = []
	if s[0] == 'A':
		f = 0
	else:
		f = 1
	for i in range(1 + n):
		if s[i] == 'A' and f == 0:
			continue
		elif f != 1:
			f = 1
			re.append([a, i])
			if s[i] == '#':
				re[-1][1] -= 1
		elif s[i] == 'B' and f == 1:
			continue
		elif f != 0:
			f = 0
			re.append([b, i])
			if s[i] == '#':
				re[-1][1] -= 1
	if s[-2] != s[-3]:
		re.pop()
	cur = 0
	for i in re:
		cur += i[0]
	g = 0
	if len(re) == 1:
		if s[0] == 'A' and p >= a or (s[0] == 'B' and p >= b):
			print(1)
			continue
		else:
			print(len(s) - 1)
			continue
	polo = 0
	while cur > p and g < len(re):
		cur -= re[g][0]
		polo = 1
		g += 1
	if polo == 0:
		print(1)
	else:
		print(re[g - 1][1] + 1)


for t in range(int(input())):
	(a, b, p) = [int(i) for i in input().split()]
	s = input()[::-1]
	n = len(s)
	curr = s[1]
	res = 0
	for i in range(1, n):
		if s[i] != curr:
			if curr == 'A':
				p -= a
				curr = 'B'
			else:
				p -= b
				curr = 'A'
			if p < 0:
				break
			else:
				res = i - 1
	if curr == 'A':
		p -= a
	else:
		p -= b
	if p < 0:
		print(n - res)
	else:
		print(1)


n = int(input())
for i in range(n):
	(a, b, p) = map(int, input().split())
	s = input()
	t = len(s)
	l = [0]
	for j in range(t - 1):
		if s[t - 2 - j] == s[t - 1 - j] and j != 0:
			l.append(l[j])
		elif s[t - 2 - j] == 'B':
			l.append(l[j] + b)
		else:
			l.append(l[j] + a)
	l.reverse()
	v = len(l) - 1
	for k in range(len(l)):
		if p >= l[k]:
			v = k
			break
	print(v + 1)


import sys

def metod(x):
	if t[x] == 'A':
		q = a
	else:
		q = b
	for i in range(x + 1, len(t) - 1):
		if t[i] != t[i - 1]:
			if t[i] == 'A':
				q += a
			else:
				q += b
	return q
for morzer in range(int(input())):
	(a, b, p) = map(int, input().split())
	t = list(input())
	(l, r) = (-1, len(t) - 1)
	while r - l > 1:
		mid = (r + l) // 2
		if metod(mid) > p:
			l = mid
		else:
			r = mid
	print(r + 1)


def oki(a, b, p, lst):
	lst.pop()
	while lst:
		s = lst[-1]
		t = 0
		if s == 'A':
			t = a
		elif s == 'B':
			t = b
		if t > p:
			break
		p -= t
		while lst and lst[-1] == s:
			lst.pop()
	print(len(lst) + 1)
for _ in range(int(input())):
	(a, b, p) = map(int, input().split(' '))
	lst = list(input().strip())
	oki(a, b, p, lst)


from sys import stdin, stdout

def solve(a, b, p, crossroads):
	ref = {'A': a, 'B': b, '#': 0}
	crossroads = '#' + crossroads[:-1] + '#'
	i = last = len(crossroads) - 1
	while i > 0:
		if crossroads[i - 1] != crossroads[i]:
			if p >= ref[crossroads[i]]:
				p -= ref[crossroads[i]]
				last = i
			else:
				return last
		i -= 1
	return 1

def main():
	n = int(stdin.readline().rstrip())
	for _ in range(n):
		(a, b, p) = [int(x) for x in stdin.readline().rstrip().split()]
		crossroads = stdin.readline().rstrip()
		val = solve(a, b, p, crossroads)
		stdout.write(f'{val}\n')
main()


t = int(input())
for _ in range(t):
	(a, b, p) = map(int, input().split())
	s = list(input())
	n = len(s)
	flg = 0
	ans = n
	y = 'C'
	k = 0
	while s:
		x = s.pop()
		if not flg:
			flg = 1
			continue
		if x == y:
			ans -= 1
			continue
		else:
			if x == 'A':
				if p < a:
					print(ans)
					k = 1
					break
				else:
					p -= a
			if x == 'B':
				if p < b:
					print(ans)
					k = 1
					break
				else:
					p -= b
		y = x
		ans -= 1
	if s == [] and k == 0:
		print(1)


def solve(a, b, p, s):
	n = len(s) - 1
	pref = [0] * n
	if s[1] == 'A':
		pref[1] = a
	else:
		pref[1] = b
	for i in range(2, n):
		if s[i] == s[i - 1]:
			pref[i] = pref[i - 1]
		elif s[i] == 'A':
			pref[i] = pref[i - 1] + a
		else:
			pref[i] = pref[i - 1] + b
	i = 1
	while i < n:
		if i == 1:
			if pref[n - 1] - pref[i - 1] <= p:
				print(i)
				return
			else:
				i += 1
		elif s[i] == s[i - 1]:
			i += 1
			continue
		elif pref[n - 1] - pref[i - 1] <= p:
			print(i)
			return
		else:
			i += 1
			continue
	print(n)
t = int(input())
for _ in range(t):
	(a, b, p) = map(int, input().split())
	s = list(input())
	s.insert(0, 0)
	solve(a, b, p, s)


import sys
from collections import defaultdict as dd
from collections import deque
from functools import *
from fractions import Fraction as f
from copy import *
from bisect import *
from heapq import *
from itertools import permutations, product

def eprint(*args):
	print(*args, file=sys.stderr)
zz = 1
if zz:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('all.txt', 'w')

def inc(d, c):
	d[c] = d[c] + 1 if c in d else 1

def bo(i):
	return ord(i) - ord('A')

def li():
	return [int(xx) for xx in input().split()]

def fli():
	return [float(x) for x in input().split()]

def comp(a, b):
	if a > b:
		return 2
	return 2 if a == b else 0

def gi():
	return [xx for xx in input().split()]

def fi():
	return int(input())

def pro(a):
	return reduce(lambda a, b: a * b, a)

def swap(a, i, j):
	(a[i], a[j]) = (a[j], a[i])

def si():
	return list(input().rstrip())

def mi():
	return map(int, input().split())

def gh():
	sys.stdout.flush()

def isvalid(i, j):
	return 0 <= i < n and 0 <= j < n

def graph(n, m):
	for i in range(m):
		(x, y) = mi()
		a[x].append(y)
		a[y].append(x)
t = fi()
while t > 0:
	t -= 1
	(a, b, p) = mi()
	s = si()
	n = len(s) - 1

	def can(mid):
		i = mid
		c = 0
		while i < n:
			j = i
			while j < n and s[i] == s[j]:
				j += 1
			if s[i] == 'A':
				c += a
			else:
				c += b
			i = j
		return c <= p
	l = 0
	r = ans = n
	while l <= r:
		mid = (l + r) // 2
		if can(mid):
			ans = mid + 1
			r = mid - 1
		else:
			l = mid + 1
	print(ans)


for __ in range(int(input())):
	(a, b, p) = [int(x) for x in input().split()]
	s = input()
	if p < a and p < b:
		print(len(s))
	else:
		n = len(s)
		cost = [-1] * n
		if s[0] == 'A':
			cost[0] = a
		else:
			cost[0] = b
		ind = []
		ind.append(0)
		for i in range(1, n):
			if s[i - 1] == s[i]:
				cost[i] = 0
			else:
				if s[i] == 'B':
					cost[i] = b
				else:
					cost[i] = a
				ind.append(i)
		if cost[n - 1] == -1:
			cost[n - 1] = 0
		for i in range(n - 3, -1, -1):
			cost[i] += cost[i + 1]
		f = 0
		for i in ind:
			if p >= cost[i]:
				f = 1
				print(i + 1)
				break
		if f == 0:
			print(n)


import sys
t = int(sys.stdin.readline())
for _ in range(t):
	(a, b, p) = [int(d) for d in sys.stdin.readline().split()]
	s = sys.stdin.readline()
	lsy = None
	c = len(s) - 1
	for sy in s[-3::-1]:
		if sy == 'A' and sy != lsy:
			p -= a
		elif sy == 'B' and sy != lsy:
			p -= b
		if p < 0:
			print(c)
			break
		else:
			c -= 1
		lsy = sy
	else:
		print(1)


t = int(input())
for j in range(t):
	(a, b, p) = [int(i) for i in input().split()]
	s = input()
	l = len(s) - 2
	r = 'R'
	x = True
	while l >= 0:
		if r != s[l]:
			if s[l] == 'A':
				p = p - a
			elif s[l] == 'B':
				p = p - b
			r = s[l]
		if p < 0:
			print(l + 2)
			x = False
			break
		l = l - 1
	if x == True:
		print(1)


T = int(input())
while T != 0:
	T -= 1
	(a, b, p) = (int(x) for x in input().split())
	s = input()
	n = len(s)
	arr = [0] * n
	if s[n - 2] == 'A':
		arr[n - 2] = a
	else:
		arr[n - 2] = b
	for i in range(n - 3, -1, -1):
		if s[i] == s[i + 1]:
			arr[i] = arr[i + 1]
		elif s[i] == 'A':
			arr[i] = a + arr[i + 1]
		else:
			arr[i] = b + arr[i + 1]
	ans = n
	for i in range(n):
		if arr[i] <= p:
			ans = i + 1
			break
	print(ans)


from sys import stdin
input = stdin.readline

def read():
	(a, b, p) = map(int, input().split())
	s = input()[:-1]
	return (a, b, p, s)

def solve(a, b, p, s):
	ticket = None
	for i in range(len(s) - 2, -1, -1):
		if s[i] != ticket:
			p -= a if s[i] == 'A' else b
			ticket = s[i]
			if p < 0:
				return i + 2
	return 1
for t in range(int(input())):
	result = solve(*read())
	print(result)


from itertools import groupby
for q in range(int(input())):
	(a, b, p) = map(int, input().split())
	s = input()
	si = len(s)
	ind = 0
	d = []
	tol = 0
	for (i, j) in groupby(s):
		if i == 'A':
			yy = len(list(j))
			d.append(((ind, yy + ind), a))
			ind += yy
		else:
			yy = len(list(j))
			d.append(((ind, yy + ind), b))
			ind += yy
		tol += 1
		if ind >= si - 1:
			break
	res = 1
	for i in range(tol - 1, -1, -1):
		if p >= d[i][1]:
			p -= d[i][1]
		else:
			res = d[i][0][1] + 1
			p = -2
			break
	if p == -2:
		print(min(res, si))
	else:
		print(1)


for T in range(int(input())):
	(b, a, p) = map(int, input().split(' '))
	s = ' ' + input()[::-1]
	cost = 0
	i_min = 1
	pre = 'A' if s[2] == 'B' else 'B'
	while i_min < len(s) - 1:
		j = i_min + 1
		if pre == 'A':
			while j < len(s):
				if j == len(s) - 1 or (s[j] == 'B' and s[j + 1] == 'A'):
					break
				j += 1
			if cost + a <= p:
				cost += a
				i_min = j
				pre = 'B'
			else:
				break
		else:
			while j < len(s):
				if j == len(s) - 1 or (s[j] == 'A' and s[j + 1] == 'B'):
					break
				j += 1
			if cost + b <= p:
				cost += b
				i_min = j
				pre = 'A'
			else:
				break
	print(len(s) - i_min)


for _ in range(int(input())):
	(a, b, p) = map(int, input().split())
	s = input()
	n = len(s)
	(l, c) = ([], 0)
	for i in range(n - 2, 0, -1):
		if s[i - 1] != s[i]:
			if s[i] == 'A':
				l.append((c + a, i + 1))
				c += a
			else:
				l.append((c + b, i + 1))
				c += b
	if s[0] == 'A':
		l.append((c + a, 1))
	else:
		l.append((b + c, 1))
	ans = n
	for (el1, el2) in l:
		if el1 > p:
			break
		ans = el2
	print(ans)


import sys

def solve(A, B, P, S):
	S = list(S)
	if len(S) >= 2:
		if S[-1] != S[-2]:
			S[-1] = S[-2]

	def makeRepeat(s):
		repeat = [[s[0], 0]]
		for ch in s:
			if ch == repeat[-1][0]:
				repeat[-1][1] += 1
			else:
				repeat.append([ch, 1])
		return repeat
	repeats = makeRepeat(S)
	best = len(S)
	for (c, repeat) in reversed(repeats):
		if c == 'A':
			if P < A:
				break
			P -= A
			best -= repeat
		if c == 'B':
			if P < B:
				break
			P -= B
			best -= repeat
	best = min(len(S), best + 1)
	return best
input = sys.stdin.readline
T = int(input())
for t in range(T):
	(A, B, P) = map(int, input().split())
	S = input().rstrip()
	ans = solve(A, B, P, S)
	print(ans)


t = int(input())
for i in range(t):
	(a, b, p) = map(int, input().split())
	s = input()
	cur = 'C'
	fin = False
	for k in range(len(s) - 2, -1, -1):
		if fin == True:
			break
		if s[k] == cur:
			continue
		elif s[k] == 'A':
			cur = 'A'
			if p - a < 0:
				print(k + 2)
				fin = True
			p -= a
		elif s[k] == 'B':
			cur = 'B'
			if p - b < 0:
				print(k + 2)
				fin = True
			p -= b
	if fin == False:
		print(1)


def solve():
	(a, b, p) = map(int, input().split())
	s = input()
	n = len(s)
	if n == 1:
		print(1)
		return
	if n == 2:
		if s == 'AA' or s == 'AB':
			if a <= p:
				print(1)
				return
			else:
				print(2)
				return
		elif b <= p:
			print(1)
			return
		else:
			print(2)
			return
	i = 0
	dp = [0] * n
	if s[:2] == 'AA' or s[:2] == 'AB':
		dp[1] = a
	else:
		dp[1] = b
	i = 2
	while i < n:
		if s[i] != s[i - 1] and s[i - 1] == s[i - 2] or s[i] == s[i - 1] == s[i - 2]:
			dp[i] = dp[i - 1]
		elif s[i] != s[i - 1]:
			if s[i - 1] == 'A':
				dp[i] = dp[i - 1] + a
			else:
				dp[i] = dp[i - 1] + b
		elif s[i] == 'A':
			dp[i] = dp[i - 1] + a
		else:
			dp[i] = dp[i - 1] + b
		i += 1
	if dp[n - 1] <= p:
		print(1)
	else:
		t = 0
		s = dp[n - 1]
		idx = -1
		i = 0
		while i < n:
			tmp = t
			while i < n and dp[i] == t:
				idx = i
				i += 1
			if s - tmp <= p:
				break
			if i < n:
				t = dp[i]
		print(idx + 1)
	return
t = int(input())
for _ in range(t):
	solve()


import sys
inp = sys.stdin.readline
input = lambda : inp().strip()

def iin():
	return int(input())

def lin():
	return list(map(int, input().split()))

def main():
	T = iin()
	while T:
		T -= 1
		(a, b, p) = lin()
		s = list(input())
		n = len(s)
		ans = []
		ch = 'D'
		for i in range(n - 1):
			if s[i] != ch:
				ch = s[i]
				x = a
				if ch == 'B':
					x = b
				ans.append([x, i])
		l = len(ans)
		ans = ans[::-1]
		for i in range(1, l):
			ans[i][0] += ans[i - 1][0]
		ans = ans[::-1]
		for (i, j) in ans:
			if p >= i:
				print(j + 1)
				break
		else:
			print(n)
main()


for _ in ' ' * int(input()):
	(a, b, p) = map(int, input().split())
	s = list(input())
	n = len(s)
	if s[-1] == s[-2]:
		if s[-1] == 'A':
			s[-1] = 'B'
		else:
			s[-1] = 'A'
	lst = []
	ind = [1]
	iind = 1
	val = a if s[0] == 'A' else b
	for i in range(n - 1):
		if s[i] != s[i + 1]:
			lst.append(val)
			if val == a:
				val = b
			else:
				val = a
			ind.append(i + 2)
	ind.pop()
	sm = sum(lst)
	ln = len(lst)
	f = 0
	for i in range(ln):
		if sm <= p:
			f = 1
			print(ind[i])
			break
		sm -= lst[i]
	if f == 0:
		print(n)


t = int(input())
for _ in range(t):
	(a, b, p) = [int(x) for x in input().split()]
	s = input()
	s = s[:-1] + 'Z'
	c = ''
	total = 0
	for x in s:
		if c != '' and x != c:
			if c == 'A':
				total += a
			elif c == 'B':
				total += b
		c = x
	c = ''
	total2 = 0
	i = 0
	for x in s:
		i += 1
		if c != '' and x != c:
			if c == 'A':
				total2 += a
			elif c == 'B':
				total2 += b
		if total - total2 <= p:
			break
		c = x
	print(i)


def solution(a, b, p, s: str):
	tr = {'A': a, 'B': b}
	s = s[::-1]
	ln = len(s)
	curtransport = s[1]
	prices = [tr[curtransport]]
	if prices[0] > p:
		print(ln)
		return
	for i in range(1, ln):
		if curtransport == s[i]:
			prices.append(prices[i - 1])
		else:
			curtransport = s[i]
			prices.append(prices[i - 1] + tr[s[i]])
		if prices[i] > p:
			print(ln - i + 1)
			return
	print(1)
t = int(input())
for i in range(t):
	(a, b, p) = map(int, input().split())
	s = input()
	solution(a, b, p, s)


t = int(input())
for _ in range(t):
	(a, b, p) = map(int, input().split())
	s = [i for i in input()]
	n = len(s)
	c = [0] * n
	sw = s[0]
	c[0] = a if sw == 'A' else b
	for i in range(n - 1):
		if s[i] == 'A' and sw == 'B':
			sw = 'A'
			c[i] = a
		elif s[i] == 'B' and sw == 'A':
			sw = 'B'
			c[i] = b
	f = False
	for i in range(n - 2, -1, -1):
		if p < c[i]:
			j = i + 1
			while c[j] == 0 and j < n - 1:
				j += 1
			print(j + 1)
			f = True
			break
		p -= c[i]
	if not f:
		print(1)


t = int(input())
for _ in range(t):
	(a, b, p) = map(int, input().split())
	s = input()
	n = len(s)
	C = [0] * n
	cur = s[-2]
	if cur == 'A':
		C[-2] = a
	else:
		C[-2] = b
	for i in range(n - 2):
		next = s[-3 - i]
		if cur == next:
			C[-3 - i] = C[-2 - i]
		elif next == 'A':
			C[-3 - i] = C[-2 - i] + a
		else:
			C[-3 - i] = C[-2 - i] + b
		cur = next
	for i in range(n):
		if C[i] <= p:
			print(i + 1)
			break


t = int(input())
for _ in range(t):
	(a, b, p) = map(int, input().split())
	r = {'A': a, 'B': b}
	s = input()
	n = len(s)
	rs = [0] * n
	next = ''
	for i in range(n - 1):
		j = n - i - 2
		rs[j] = rs[j + 1]
		if next != s[j]:
			rs[j] += r[s[j]]
		next = s[j]
	for i in range(n):
		if rs[i] <= p:
			break
	print(i + 1)


for t in range(int(input())):
	(a, b, p) = list(map(int, input().split()))
	s = input()
	road = [a if s[0] == 'A' else b]
	st = [0]
	for i in range(1, len(s) - 1):
		if s[i] != s[i - 1]:
			road.append(road[-1] + (a, b)[s[i] == 'B'])
			st.append(i)
	pay = road[-1]
	j = 0
	while pay > p and j < len(st):
		pay = road[-1] - road[j]
		j += 1
	print(st[j] + 1 if j < len(st) else len(s))


for i in range(int(input())):
	(a, b, p) = map(int, input().split())
	string = input()
	crossroads = len(string)
	(money, answer) = (0, crossroads)
	for i in range(crossroads - 1):
		if crossroads - 2 - i == 0:
			if string[0] == 'A':
				money += a
			else:
				money += b
			if money <= p:
				answer = crossroads - 1 - i
			print(answer)
			break
		if string[crossroads - 2 - i] != string[crossroads - 3 - i]:
			if string[crossroads - 2 - i] == 'A':
				money += a
			else:
				money += b
			if money <= p:
				answer = crossroads - 1 - i
			else:
				print(answer)
				break


from collections import Counter as C, defaultdict as D, deque as Q
from operator import itemgetter as I
from itertools import product as P, permutations as PERMUT
from bisect import bisect_left as BL, bisect_right as BR, insort as INSORT
from heapq import heappush as HPUSH, heappop as HPOP
from math import floor as MF, ceil as MC, gcd as MG, factorial as F, sqrt as SQRT, inf as INFINITY, log as LOG
from sys import stdin, stdout
INPUT = stdin.readline
PRINT = stdout.write
L = list
M = map

def Player1():
	print('')

def Player2():
	print('')

def Yes():
	PRINT('Yes\n')

def No():
	PRINT('No\n')

def IsPrime(n):
	for i in range(2, MC(SQRT(n)) + 1):
		if n % i == 0:
			return False
	return True

def Factors(x):
	ans = []
	for i in range(1, MC(SQRT(x)) + 1):
		if x % i == 0:
			ans.append(i)
			if x % (x // i) == 0:
				ans.append(x // i)
	return ans

def CheckPath(source, destination, g):
	visited = [0] * 101
	q = Q()
	q.append(source)
	visited[source] = 1
	while q:
		node = q.popleft()
		if node == destination:
			return 1
		for v in g[node]:
			if not visited[v]:
				q.append(v)
				visited[v] = 1
	return 0

def Sieve(n):
	prime = [1] * (n + 1)
	p = 2
	while p * p <= n:
		if prime[p]:
			for i in range(p * p, n + 1, p):
				prime[i] = 0
		p += 1
	primes = []
	for p in range(2, n + 1):
		if prime[p]:
			primes.append(p)
	return primes

def Prefix(a, n):
	p = []
	for i in range(n):
		if i == 0:
			p.append(a[0])
		else:
			p.append(p[-1] + a[i])
	return p

def Suffix(a, n):
	s = [0] * n
	for i in range(n - 1, -1, -1):
		if i == n - 1:
			s[i] = a[i]
		else:
			s[i] = s[i + 1] + a[i]
	return s

def Spf(n):
	spf = [0 for i in range(n)]
	spf[1] = 1
	for i in range(2, n):
		spf[i] = i
	for i in range(4, n, 2):
		spf[i] = 2
	for i in range(3, MC(SQRT(n)) + 1):
		if spf[i] == i:
			for j in range(i * i, n, i):
				if spf[j] == j:
					spf[j] = i
	return spf

def DFS(g, s, visited, ans):
	visited[s] = 1
	for (u, c) in g[s]:
		if visited[u]:
			continue
		if c == ans[s]:
			if c == 1:
				ans[u] = 2
			else:
				ans[u] = 1
		else:
			ans[u] = c
		DFS(g, u, visited, ans)

def Main():
	for _ in range(int(INPUT())):
		(a, b, c) = M(int, INPUT().split())
		s = INPUT()
		n = len(s) - 1
		ans = n
		i = n - 2
		tmp = 0
		d = {}
		d['A'] = a
		d['B'] = b
		while i >= 0:
			j = i
			while j >= 0 and s[j] == s[i]:
				j -= 1
			tmp += d[s[i]]
			i = j
			if tmp <= c:
				ans = i + 2
		PRINT('%d\n' % ans)
Main()


import math
import bisect

def rints():
	return list(map(int, input().split()))
t = int(input())
for _ in range(t):
	(a, b, p) = rints()
	s = input()
	pos = len(s) - 1
	price = {'A': a, 'B': b}
	total = 0
	while pos > 0 and total + price[s[pos - 1]] <= p:
		total += price[s[pos - 1]]
		means = s[pos - 1]
		while pos > 0 and s[pos - 1] == means:
			pos -= 1
	print(pos + 1)


t = int(input())
for i in range(t):
	(a, b, p) = map(int, input().split())
	s = input()
	f = True
	for i in range(len(s) - 2, -1, -1):
		if s[i] == 'A':
			if a > p:
				print(i + 2)
				f = False
				break
			if s[i] != s[i - 1]:
				p = p - a
		if s[i] == 'B':
			if b > p:
				print(i + 2)
				f = False
				break
			if s[i] != s[i - 1]:
				p = p - b
	if f:
		print(1)


t = int(input())
for tt in range(t):
	(a, b, p) = map(int, input().split())
	ar = input()
	i = 0
	c = 1
	d = [[ar[0], i]]
	for r in range(1, len(ar)):
		if ar[r - 1] != ar[r]:
			d.append([ar[r], r])
	if len(d) > 1 and d[-1][1] == len(ar) - 1:
		d.pop()
	for k in d:
		if k[0] == 'A':
			k.append(a)
		else:
			k.append(b)
	n = len(d) - 1
	while n >= 0:
		if d[n][-1] <= p:
			p -= d[n][-1]
			n -= 1
		else:
			break
	if n == -1:
		print(1)
	elif n == len(d) - 1:
		print(len(ar))
	else:
		print(d[n + 1][1] + 1)


for _ in range(int(input())):
	(a, b, p) = map(int, input().split())
	s = input()[::-1]
	s = s[1:]
	c = 0
	f = not s[0] == 'A'
	f1 = True
	k = 0
	for i in s:
		k -= 1
		if i == 'A':
			if not f:
				c += a
			f = True
		else:
			if f:
				c += b
			f = False
		if c > p:
			f1 = False
			break
	print(len(s) + 1 + k if f1 else len(s) + 2 + k)


import sys

def main():

	def pro(x):
		if s[x] == 'A':
			ans = a
		else:
			ans = b
		for i in range(x + 1, len(s) - 1):
			if s[i] != s[i - 1]:
				if s[i] == 'A':
					ans += a
				else:
					ans += b
		return ans

	def res(s):
		l = -1
		r = len(s) - 1
		while r - l > 1:
			mid = (r + l) // 2
			if pro(mid) > p:
				l = mid
			else:
				r = mid
		return r
	(a, b, p) = [int(i) for i in sys.stdin.readline().split()]
	s = list(input())
	print(res(s) + 1)
for test in range(int(sys.stdin.readline())):
	main()


import math, collections, sys

def solve():
	(a, b, p) = map(int, input().split())
	s = input()
	z = []
	for i in range(len(s) - 1):
		if not z:
			z.append([s[i], i + 1])
			continue
		if z[-1][0] != s[i]:
			z.append([s[i], i + 1])
	z = z[::-1]
	(na, nb) = (0, 0)
	for i in z:
		if i[0] == 'A':
			na += 1
		else:
			nb += 1
	tc = na * a + nb * b
	while tc > p and z:
		nxt = z.pop()
		if nxt[0] == 'A':
			na -= 1
		else:
			nb -= 1
		tc = na * a + nb * b
	if not z:
		print(len(s))
	else:
		print(z[-1][1])
for _ in range(int(input())):
	solve()


for _ in range(int(input())):
	(a, b, p) = map(int, input().split())
	s = input()
	n = len(s)
	st = [1]
	for i in range(1, n - 1):
		if s[i] != s[i - 1]:
			st.append(i + 1)
	st.append(n)
	if s[0] == 'A':
		pr = [a, b]
	else:
		pr = [b, a]
	sum = 0
	l = len(st)
	l -= 2
	while p >= 0:
		if l == -1:
			p -= 10 ** 6
		else:
			p -= pr[l % 2]
		l -= 1
	print(st[l + 2])


t = int(input())
while t:
	(a, b, p) = map(int, input().split())
	s = input()
	s = s[::-1]
	i = 1
	while i < len(s):
		if s[i] == 'A':
			if p < a:
				break
			else:
				while i < len(s) and s[i] == 'A':
					i += 1
				p -= a
		elif p < b:
			break
		else:
			while i < len(s) and s[i] == 'B':
				i += 1
			p -= b
	if i == 1:
		print(len(s))
	elif i >= len(s):
		print(1)
	else:
		print(len(s) - i + 1)
	t -= 1


te = int(input())
while te > 0:
	te -= 1
	(a, b, p) = list(map(int, input().split()))
	crossRoads = input()
	dp = list()
	dp.append((1, 0))
	currentSum = 0
	i = 1
	l = len(crossRoads)
	while i < l:
		if crossRoads[i] != crossRoads[i - 1]:
			if crossRoads[i] == 'B':
				currentSum += a
			else:
				currentSum += b
			dp.append((i + 1, currentSum))
		i += 1
	if crossRoads[l - 1] == crossRoads[l - 2]:
		if crossRoads[l - 1] == 'A':
			currentSum += a
		else:
			currentSum += b
		dp.append((l, currentSum))
	dl = len(dp)
	i = 0
	ans = 1
	while i < dl:
		if dp[dl - 1][1] - dp[i][1] <= p:
			ans = dp[i][0]
			break
		i += 1
	print(ans)


def main(a, b, c, mot):
	n = len(mot)
	i = n - 2
	if mot[i] == 'A':
		test = True
		if c < a:
			return i + 1
		c -= a
	else:
		test = False
		if c < b:
			return i + 1
		c -= b
	while i > 0:
		cur = mot[i - 1]
		if test and cur != 'A':
			test = False
			if c < b:
				return i
			c -= b
		if not test and cur != 'B':
			test = True
			if c < a:
				return i
			c -= a
		i -= 1
	return i
n = int(input())
for _ in range(n):
	lst = list(map(int, input().split()))
	(a, b, c) = (lst[0], lst[1], lst[2])
	mot = input()
	print(main(a, b, c, mot) + 1)


from math import inf
t = int(input())
for q in range(t):
	(a, b, p) = [int(i) for i in input().split()]
	s = input()
	l = len(s)
	dp = [0] * l
	if s[l - 2] == 'A':
		dp[l - 2] = a
	else:
		dp[l - 2] = b
	for i in range(l - 3, -1, -1):
		if s[i] == s[i + 1]:
			dp[i] = dp[i + 1]
		elif s[i] == 'A':
			dp[i] = dp[i + 1] + a
		else:
			dp[i] = dp[i + 1] + b
	for i in range(l):
		if p >= dp[i]:
			print(i + 1)
			break


n = int(input())
while n > 0:
	numbers = list(map(int, input().split()))[:3]
	a = numbers[0]
	b = numbers[1]
	p = numbers[2]
	s = input()
	l = len(s)
	flag = 0
	flag1 = 0
	c = 0
	m = 0
	for i in range(l - 1, 0, -1):
		if s[i] == s[i - 1]:
			c += 1
		else:
			flag1 = 1
			if c == 0:
				if s[i - 1] == 'A':
					if p - a >= 0:
						p = p - a
					else:
						flag = 1
				elif p - b >= 0:
					p = p - b
				else:
					flag = 1
				m = i - 1
				break
			else:
				if s[i] == 'A':
					if p - a >= 0:
						p = p - a
					else:
						flag = 1
				elif p - b >= 0:
					p = p - b
				else:
					flag = 1
				m = i
				break
	if flag1 == 0 and s[0] == 'A':
		if p - a >= 0:
			print('1')
		else:
			print(l)
		n = n - 1
		continue
	elif flag1 == 0 and s[0] == 'B':
		if p - b >= 0:
			print('1')
		else:
			print(l)
		n = n - 1
		continue
	elif flag == 1 and c == 0:
		print(m + 2)
		n = n - 1
		continue
	elif flag == 1:
		print(m + c + 1)
		n = n - 1
		continue
	c = 0
	flag1 = 0
	for i in range(m, 0, -1):
		if s[i] == s[i - 1]:
			c += 1
		else:
			flag1 = 1
			if s[i - 1] == 'A':
				if p - a >= 0:
					p = p - a
					c = 0
				else:
					flag = 1
					m = i
					break
			elif p - b >= 0:
				p = p - b
				c = 0
			else:
				flag = 1
				m = i
				break
	if flag == 1:
		c = 0
		print(m + 1)
	else:
		print('1')
	n = n - 1


t = int(input())
ans = []
for i in range(0, t):
	(a, b, p) = map(int, input().split())
	road = str(input())
	ans.append(len(road))
	flag = 0
	n = len(road) - 1
	sum = 0
	if n == 0:
		ans[i] = 1
	else:
		for j in range(0, n):
			if road[n - j - 1] == 'A':
				if flag == 1 and p >= sum:
					ans[i] = n - j
				if flag != 1:
					flag = 1
					sum += a
					if p >= sum:
						ans[i] = n - j
					else:
						break
			else:
				if flag == -1 and p >= sum:
					ans[i] = n - j
				if flag != -1:
					flag = -1
					sum += b
					if p >= sum:
						ans[i] = n - j
					else:
						break
for i in range(0, t):
	print(ans[i])


t = int(input())
for _ in range(t):
	(a, b, p) = map(int, input().split())
	s = input()
	n = len(s)
	ans = n
	now = s[n - 2]
	idx = n - 1
	for i in reversed(range(n - 2)):
		if now != s[i]:
			p -= a if now == 'A' else b
			now = s[i]
			if p < 0:
				break
			else:
				ans = idx
				idx = i + 1
		else:
			idx = i + 1
	else:
		p -= a if now == 'A' else b
		if p >= 0:
			ans = 1
	print(ans)


T = int(input())
for _ in range(T):
	(a1, b, c) = map(int, input().split())
	s = input()
	s = 'C' + s
	a = s[len(s) - 2]
	tc = 0
	rv = len(s) - 1
	flag = 0
	for w in range(len(s) - 3, -1, -1):
		i = s[w]
		if i != a:
			if a == 'B':
				tc = tc + b
				if tc > c:
					flag = 1
					print(rv)
					break
			else:
				tc = tc + a1
				if tc > c:
					flag = 1
					print(rv)
					break
			rv = w + 1
		a = i
	if flag != 1:
		print(1)


import sys
from collections import Counter

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
for _ in range(INT()):
	(a, b, p) = MAP()
	S = input()
	N = len(S)
	nxt = [0] * N
	tmp = N - 1
	nxt[N - 1] = tmp
	for i in range(N - 2, -1, -1):
		if S[i] == S[i + 1]:
			nxt[i] = tmp
		else:
			tmp = i + 1
			nxt[i] = tmp
	dp = [INF] * N
	dp[0] = 0
	for i in range(N - 1):
		if S[i] == 'A':
			dp[nxt[i]] = min(dp[nxt[i]], dp[i] + a)
		else:
			dp[nxt[i]] = min(dp[nxt[i]], dp[i] + b)
	ans = N
	total = dp[N - 1]
	for i in range(N - 1, -1, -1):
		if dp[i] == INF:
			continue
		cost = total - dp[i]
		if cost <= p:
			ans = i + 1
		else:
			break
	print(ans)


t = int(input())
for i in range(t):
	(a, b, p) = map(int, input().split())
	s = input()
	if len(s) == 1:
		print(1)
		continue
	l = 0
	ans = len(s)
	for i in range(len(s) - 2, -1, -1):
		if i == 0 or s[i] != s[i - 1]:
			if s[i] == 'A':
				l += a
			else:
				l += b
			if l <= p:
				ans = i + 1
	print(ans)


for _ in range(int(input())):
	(a, b, p) = map(int, input().split())
	s = list(input())
	ind = 0
	price = 0
	check = ''
	change = []
	while ind < len(s) - 1:
		if s[ind] == 'A':
			if check != s[ind]:
				price += a
				check = s[ind]
				change.append(ind)
		if s[ind] == 'B':
			if check != s[ind]:
				price += b
				check = s[ind]
				change.append(ind)
		ind += 1
	need = price - p
	if need <= 0:
		print(1)
	else:
		ind = 0
		price = 0
		check = ''
		while ind < len(s) - 1:
			if s[ind] == 'A':
				if check != s[ind]:
					price += a
					check = s[ind]
			if s[ind] == 'B':
				if check != s[ind]:
					price += b
					check = s[ind]
			ind += 1
			if price >= need:
				break
		change.append(len(s) - 1)
		for i in change:
			if i >= ind:
				ind = i
				break
		print(ind + 1)


t = int(input())
for i in range(t):
	cost = []
	cs = 0
	ans = 1
	ls2 = []
	ls1 = [int(a) for a in input().split()]
	(a, b, p) = (ls1[0], ls1[1], ls1[2])
	s = str(input())
	for aa in s:
		ls2.append(aa)
		l = ls2[0]
		ind = 0
	for j in range(1, len(ls2)):
		if l != ls2[j] or j == len(ls2) - 1:
			if l == 'A':
				cost.append([a, j - ind])
			else:
				cost.append([b, j - ind])
			l = ls2[j]
			ind = j
		else:
			pass
	for k in range(1, len(cost) + 1):
		cs += cost[-k][0]
		if cs > p:
			break
		else:
			pass
	if cs <= p:
		ans = 1
	else:
		for z in range(len(cost) - (k - 1)):
			ans += cost[z][1]
	print(ans)


for _ in range(int(input())):
	(a, b, p) = list(map(int, input().split()))
	string = input()
	ans = len(string)
	for i in range(len(string) - 2, 0, -1):
		if string[i] != string[i - 1]:
			if string[i] == 'A':
				p -= a
			else:
				p -= b
			if p < 0:
				break
			ans = i + 1
			if p == 0:
				break
	if string[0] == 'A':
		if p >= a:
			ans = 1
	elif p >= b:
		ans = 1
	print(ans)


from sys import stdin
input = stdin.readline
t = int(input())
for _ in range(t):
	(a, b, p) = list(map(int, input().split()))
	s = input()
	dict = {}
	dict['A'] = a
	dict['B'] = b
	tmp = s[:-1]
	s = s[:-2]
	arr = []
	vv = 0
	dic = {}
	for ii in range(len(s)):
		if arr == []:
			arr += [s[ii]]
			dic[vv] = ii
			vv += 1
		elif s[ii] != arr[-1]:
			arr += [s[ii]]
			dic[vv] = ii
			vv += 1
	arr = arr[::-1]
	a = [dict[arr[0]]]
	v = a[0]
	for i in range(1, len(arr)):
		v += dict[arr[i]]
		a += [v]
	a = a[::-1]
	idx = -1
	for i in range(len(a)):
		if a[i] <= p:
			idx = i
			break
	if idx == -1:
		print(len(s) + 1)
	else:
		print(dic[idx] + 1)


kl = int(input())
for l in range(kl):
	(a, b, p) = [int(i) for i in input().split()]
	s = str(input())
	s = s[::-1] + 'C'
	ab = 'BA'
	sb = [a, b]
	pr = 1
	kos = 1
	if s[1] == 'A':
		t = 0
	else:
		t = 1
	k = 1
	while p >= sb[t]:
		if k == -1:
			pr = 0
			break
		k = s.find(ab[t], k + 1)
		kos += k
		p -= sb[t]
		t = (t + 1) % 2
	if pr == 0 or k == -1:
		print(1)
	else:
		print(len(s) - k)


t = int(input(''))
pt = [0] * t
for x in range(0, t):
	nekaj = input('').split()
	a = int(nekaj[0])
	b = int(nekaj[1])
	p = int(nekaj[2])
	pot = input('')
	if pot != '':
		pot = 'X' + pot[:-1]
	else:
		pot = 'X'
	letter = pot[-1:]
	cost = 0
	while True:
		letter = pot[-1:]
		if letter == 'A':
			cost = a
		elif letter == 'B':
			cost = b
		else:
			break
		if p < cost:
			break
		else:
			p -= cost
			while True:
				if letter == pot[-1:]:
					pot = pot[:-1]
				else:
					break
	pt[x] = len(pot)
for y in range(0, t):
	print(pt[y])


from math import *
from collections import *
from functools import *
from bisect import *
from itertools import *
from heapq import *
from statistics import *
inf = float('inf')
ninf = -float('inf')
ip = input
alphal = 'abcdefghijklmnopqrstuvwxyz'
alphau = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

def ipl():
	return list(map(int, ip().split()))

def ipn():
	return int(ip())

def ipf():
	return float(ip())

def solve():
	(a, b, p) = ipl()
	s = ip()
	n = len(s)
	i = n - 2
	while i >= 0:
		if s[i] == 'A':
			p -= a
		elif s[i] == 'B':
			p -= b
		if p < 0:
			print(i + 2)
			return
		while i > 0 and s[i] == s[i - 1]:
			i -= 1
		i -= 1
	print(1)
	return
for _ in range(ipn()):
	solve()


t = int(input())
for _ in range(t):
	(a, b, p) = map(int, input().split())
	raw = input()
	l = len(raw)
	for i in range(l - 1)[::-1]:
		if raw[i + 1] != raw[i] or i == l - 2:
			if raw[i] == 'A':
				p -= a
			else:
				p -= b
			if p < 0:
				print(i + 2)
				break
	else:
		print(1)


I = input
for _ in range(int(I())):
	(a, b, p) = map(int, I().split())
	s = list(I())
	ind = []
	cost = []
	t = s[0]
	t1 = 0
	if s[len(s) - 1] == s[len(s) - 2]:
		t1 = 1
	for i in range(len(s)):
		if s[i] == t:
			ind.append(i + 1)
			c = a if t == 'A' else b
			cost.append(c)
			t = 'B' if t == 'A' else 'A'
	if t1 == 0:
		cost[len(cost) - 1] = 0
	tc = sum(cost)
	ind.append(len(s))
	if tc <= p:
		print('1')
	else:
		cc = 0
		for i in range(len(cost)):
			cc += cost[i]
			if tc - cc <= p:
				print(ind[i + 1])
				break


t = int(input())
for _ in range(t):
	(a, b, p) = list(map(int, input().split()))
	c = input()
	valid = True
	cur = 'C'
	for i in range(len(c) - 2, -1, -1):
		if c[i] == cur:
			continue
		elif c[i] == 'A':
			cur = c[i]
			if p - a < 0:
				print(i + 2)
				valid = False
				break
			p -= a
		else:
			cur = c[i]
			if p - b < 0:
				print(i + 2)
				valid = False
				break
			p -= b
	if valid:
		print(1)


def indexOfTheSameLetter(j, path, letter):
	count = 0
	i = j
	while path[i] == letter and i >= 0:
		count += 1
		i -= 1
		if i < 0:
			break
	return count
testCases = int(input())
for t in range(testCases):
	(a, b, p) = map(int, input().rstrip().split())
	path = list(input())
	index = len(path) - 1
	while index > 0:
		if path[index - 1] == 'A':
			c = indexOfTheSameLetter(index - 1, path, 'A')
			p -= a
			if p < 0:
				break
			else:
				index -= c
		elif path[index - 1] == 'B':
			c = indexOfTheSameLetter(index - 1, path, 'B')
			p -= b
			if p < 0:
				break
			else:
				index -= c
	print(index + 1)


t = int(input())
res = [0] * t
for i in range(t):
	(a, b, p) = input().split()
	a = int(a)
	b = int(b)
	p = int(p)
	s = input()
	l = len(s)
	if s[l - 2] == 'A':
		m = a
	else:
		m = b
	j = l - 2
	while j >= 1:
		if m > p:
			j += 1
			break
		if s[j - 1] != s[j] and s[j - 1] == 'A':
			m += a
		if s[j - 1] != s[j] and s[j - 1] == 'B':
			m += b
		j -= 1
	if j == 0 and m > p:
		j = 1
	res[i] = j + 1
for i in range(t):
	print(res[i])


t = int(input())
test_cases = [(input(), input()) for i in range(t)]

def solve(test_case):
	(a, b, p) = map(int, test_case[0].split())
	s = test_case[1]
	s = s[::-1]
	ans = len(s)
	last = s[0]
	last_path = True
	for i in range(1, len(s)):
		if s[i] != last:
			if last_path:
				if i > 1:
					if last == 'A' and p >= a:
						p -= a
					elif last == 'B' and p >= b:
						p -= b
					else:
						break
				last_path = False
			if s[i] == 'A' and p >= a:
				p -= a
			elif s[i] == 'B' and p >= b:
				p -= b
			else:
				break
		last = s[i]
		ans -= 1
	if last_path:
		if last == 'A' and p >= a:
			ans = 1
		elif last == 'B' and p >= b:
			ans = 1
		else:
			ans = len(s)
	print(ans)
for test_case in test_cases:
	solve(test_case)


TC = int(input())

def solve(s, p, a, b):
	i = len(s) - 2
	start = i
	amount = 0
	while i >= -1:
		if i == -1 or s[i] != s[start]:
			amount += a if s[start] == 'A' else b
			if amount > p:
				return start + 1
			start = i
		i -= 1
	return 0
for _ in range(TC):
	(a, b, p) = map(int, input().split())
	s = input()
	print(solve(s, p, a, b) + 1)


testcases = int(input())
masterlist = []
for i in range(testcases):
	temp = list(map(int, input().split(' ')))
	a = input()
	temp.append(a)
	masterlist.append(temp)

def calcer(lis):
	str = lis[3]
	roubles = lis[2]
	busp = lis[0]
	tramp = lis[1]
	total = 0
	for i in range(len(str) - 1):
		if str[i + 1] != str[i]:
			if str[i] == 'A':
				total += busp
			elif str[i] == 'B':
				total += tramp
	if len(str) > 1:
		if str[-2] == str[-1]:
			if str[-1] == 'A':
				total += busp
			elif str[-2] == 'B':
				total += tramp
	if total <= roubles:
		return 1
	for i in range(len(str) - 1):
		if str[i + 1] != str[i]:
			if str[i] == 'A':
				total -= busp
				if total <= roubles:
					return i + 2
			elif str[i] == 'B':
				total -= tramp
				if total <= roubles:
					return i + 2
	return len(str)
for set in masterlist:
	print(calcer(set))


for _ in range(int(input())):
	(a, b, p) = map(int, input().split())
	s = input()
	Map = {'A': a, 'B': b}
	lis = [1]
	Sum = Map[s[0]]
	for i in range(1, len(s) - 1):
		if s[i] != s[i - 1]:
			Sum += Map[s[i]]
			lis.append(i + 1)
	ans = len(s)
	for i in lis:
		if Sum <= p:
			ans = i
			break
		Sum -= Map[s[i - 1]]
	print(ans)


import sys
import math
from collections import defaultdict
from collections import deque
from itertools import combinations
from itertools import permutations
input = lambda : sys.stdin.readline().rstrip()
read = lambda : list(map(int, input().split()))
go = lambda : 1 / 0

def write(*args, sep='\n'):
	for i in args:
		sys.stdout.write('{}{}'.format(i, sep))
INF = float('inf')
MOD = int(1000000000.0 + 7)
YES = 'YES'
NO = 'NO'
for _ in range(int(input())):
	try:
		(a, b, p) = read()
		s = input()
		stack = [[s[0], 1]]
		for i in s[1:-1]:
			if i == stack[-1][0]:
				stack[-1][1] += 1
			else:
				stack.append([i, 1])
		ans = len(s)
		temp = []
		if p < a and p < b:
			print(len(s))
			go()
		while stack:
			(i, j) = stack[-1]
			stack.pop()
			if i == 'A' and p >= a:
				p -= a
				ans -= j
				temp.append(j)
			elif i == 'A' and p < a:
				break
			if i == 'B' and p >= b:
				p -= b
				ans -= j
				temp.append(j)
			elif i == 'B' and p < b:
				break
		print(ans)
	except ZeroDivisionError:
		continue
	except Exception as e:
		print(e)
		continue


t = int(input())
for i in range(0, t):
	z = 0
	e = input().split()
	a = int(e[0])
	b = int(e[1])
	p = int(e[2])
	s = str(input())
	j = len(s) - 2
	r = len(s)
	c = 0
	while j >= 0:
		l = s[j]
		while s[j] == l and j >= 0:
			j -= 1
		if l == 'A':
			c += a
		else:
			c += b
		if p >= c:
			r = j + 2
	print(r)


import queue

class costing(object):

	def __init__(self, a, b):
		self.a = a
		self.b = b

	def cost(self, x):
		if x == 'A':
			return self.a
		if x == 'B':
			return self.b
t = int(input())
for i in range(0, t):
	(a, b, p) = input().split()
	a = int(a)
	b = int(b)
	p = int(p)
	c = costing(a, b)
	s = list(input())
	length = len(s)
	state = s[0]
	num = []
	num.append(0)
	stack = queue.LifoQueue()
	for j in range(0, length):
		if s[j] != state:
			stack.put(c.cost(state))
			num.append(j)
			state = s[j]
		elif j == length - 1:
			stack.put(c.cost(state))
			num.append(j)
	truth = 0
	while truth == 0:
		if stack.empty() != True:
			x = stack.get()
			if p - x >= 0:
				p -= x
				num.pop(len(num) - 1)
			else:
				truth = 1
		else:
			truth = 1
	to_walk = num[len(num) - 1] + 1
	print(to_walk)


for _ in range(int(input())):
	(a, b, p) = map(int, input().split())
	d = {'A': a, 'B': b}
	s = input()
	n = len(s)
	l = [0] * n
	l[n - 2] = d[s[n - 2]]
	for i in range(n - 3, -1, -1):
		if s[i] == s[i + 1]:
			l[i] = l[i + 1]
		else:
			l[i] = l[i + 1] + d[s[i]]
	(lo, hi) = (0, n - 1)
	ans = n
	while lo < hi:
		m = (lo + hi) // 2
		if l[m] <= p:
			hi = m
			ans = m + 1
		else:
			lo = m + 1
	print(ans)


for _ in range(int(input())):
	(a, b, p) = map(int, input().split())
	s = input()
	n = len(s)
	lasta = lastb = n - 1
	c = [0] * n
	for i in range(n - 2, -1, -1):
		if s[i] == 'A':
			c[i] = a + c[lastb]
			lasta = i
		else:
			c[i] = b + c[lasta]
			lastb = i
	for i in range(n):
		if c[i] <= p:
			print(i + 1)
			break


t = int(input())
while t > 0:
	(a, b, p) = input().split(' ')
	a = int(a)
	b = int(b)
	p = int(p)
	d = {'A': a, 'B': b}
	s1 = input()
	s = 'N' + s1
	reach = len(s1)
	taken = s[reach]
	reach -= 1
	while taken == s[reach]:
		reach -= 1
	reach += 1
	l1 = [0] * len(s)
	if reach == len(s1):
		l1[reach] = 0
	else:
		l1[reach] = d[s[reach]]
	for i in range(reach - 1, 0, -1):
		if s[i] == s[i + 1]:
			l1[i] = l1[i + 1]
		else:
			l1[i] = l1[i + 1] + d[s[i]]
	flag = 0
	for i in range(1, reach + 1, 1):
		if l1[i] <= p:
			print(i)
			flag = 1
			break
	if flag == 0:
		print(len(s1))
	t -= 1


from sys import stdin, stderr

def rl():
	return [int(w) for w in stdin.readline().split()]
(t,) = rl()
for _ in range(t):
	(a, b, p) = rl()
	s = stdin.readline().rstrip()
	r = 1
	t = ''
	for i in range(len(s) - 1, 0, -1):
		if s[i - 1] != t:
			t = s[i - 1]
			p -= a if t == 'A' else b
			if p < 0:
				r = i + 1
				break
	print(r)


for _ in range(int(input())):
	(a, b, p) = map(int, input().split())
	s = list(input())
	n = len(s)
	cost = [0 for i in range(n)]
	cost[n - 1] = 0
	cost[n - 2] = a if s[n - 2] == 'A' else b
	for i in range(n - 3, -1, -1):
		if s[i] == s[i + 1]:
			cost[i] = cost[i + 1]
		else:
			cost[i] = cost[i + 1] + (a if s[i] == 'A' else b)
	ans = 0
	for i in cost:
		if i > p:
			ans += 1
		else:
			break
	print(ans + 1)


def judge(idx, a, b, p, s):
	i = idx - 1
	n = len(s) - 1
	cost = 0
	while i < n:
		if s[i] == 'A':
			cost += a
		else:
			cost += b
		while i + 1 < n and s[i] == s[i + 1]:
			i += 1
		i += 1
	return True if cost <= p else False
for _ in range(int(input())):
	(a, b, p) = map(int, input().split())
	s = input()
	n = len(s)
	(l, r) = (1, n)
	ans = n
	while l <= r:
		mid = (l + r) // 2
		if judge(mid, a, b, p, s):
			ans = min(ans, mid)
			r = mid - 1
		else:
			l = mid + 1
	print(ans)


for _ in range(int(input())):
	(a, b, p) = map(int, input().split())
	String = input()
	prev = ''
	N = len(String)
	FLAG = 0
	paisa = [0] * N
	x = 0
	for i in range(N - 2, -1, -1):
		if String[i] == prev:
			FLAG = 1
			paisa[i] = x
		elif String[i] == 'A':
			FLAG = 1
			prev = 'A'
			x += a
			paisa[i] = x
		elif String[i] == 'B':
			FLAG = 1
			prev = 'B'
			x += b
			paisa[i] = x
	FLAG = 0
	count = 0
	for i in paisa:
		if i <= p:
			FLAG = 1
			break
		count += 1
	if FLAG == 1:
		print(count + 1)
	else:
		print(N)


import itertools
t = int(input())
for i in range(t):
	(a, b, p) = map(int, input().split())
	summ = 0
	s = list(input())
	del s[-1]
	s1 = [list(group[1]) for group in itertools.groupby(s)]
	for i in range(len(s1)):
		if s1[i][0] == 'A':
			summ += a
		else:
			summ += b
	if summ <= p:
		print(1)
	else:
		k = 1
		for i in range(len(s1)):
			if s1[i][0] == 'A':
				summ -= a
			else:
				summ -= b
			k += len(s1[i])
			if summ <= p:
				print(k)
				break


import math, sys
input = sys.stdin.readline
S = lambda : input().rstrip()
I = lambda : int(S())
M = lambda : map(int, S().split())
L = lambda : list(M())
mod1 = 1000000007
mod2 = 998244353
for _ in range(I()):
	(a, b, p) = M()
	s = S()
	dp = [0] * len(s)
	i = len(s) - 2
	while i >= 0:
		if s[i] == 'A':
			t = dp[i + 1] + a
			while i >= 0 and s[i] == 'A':
				dp[i] = t
				i -= 1
		else:
			t = dp[i + 1] + b
			while i >= 0 and s[i] == 'B':
				dp[i] = t
				i -= 1
	ans = len(s)
	for j in range(len(dp)):
		if dp[j] <= p:
			ans = j + 1
			break
	print(ans)


for _ in range(int(input())):
	(a, b, p) = map(int, input().split())
	s = input()
	v = []
	k = []
	x = s[0]
	n = 1
	for c in s[1:-1]:
		if c == x:
			n += 1
		else:
			v.append({'A': a, 'B': b}[x])
			x = c
			k.append(n)
			n = 1
	v.append({'A': a, 'B': b}[x])
	k.append(n)
	v.reverse()
	k.reverse()
	i = 0
	z = 0
	while i < len(k):
		z += v[i]
		if z > p:
			break
		i += 1
	print(sum(k[i:]) + 1)


for t in range(int(input())):
	(a, b, p) = map(int, input().split())
	s = input()
	r = len(s)
	if s[r - 2] == 'A':
		c = a
	else:
		c = b
	if c > p:
		print(r)
	else:
		i = r - 3
		while i > -1:
			if s[i] != s[i + 1]:
				if s[i] == 'A':
					c += a
				else:
					c += b
				if c > p:
					print(i + 2)
					break
			i -= 1
		else:
			print('1')


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

def gift():
	for _ in range(cou):
		(a, b, t) = [int(x) for x in input().split()]
		pattern = input()
		prev = pattern[-1]
		n = len(pattern)
		res = None
		prevpos = n
		if prev == 'B':
			if t >= b and pattern[n - 2] == 'B':
				t -= b
				prevpos -= 1
			elif t >= a and pattern[n - 2] == 'A':
				t -= a
				prevpos -= 1
				prev = pattern[-2]
			else:
				res = n
		elif t >= a and pattern[n - 2] == 'A':
			t -= a
			prevpos -= 1
		elif t >= b and pattern[n - 2] == 'B':
			t -= b
			prevpos -= 1
			prev = pattern[-2]
		else:
			res = n
		if res:
			yield res
		else:
			for i in range(n - 2):
				currpos = n - (i + 3)
				currchar = pattern[currpos]
				if currchar != prev:
					if currchar == 'A':
						if t >= a:
							t -= a
						else:
							res = currpos + 2
							break
					elif t >= b:
						t -= b
					else:
						res = currpos + 2
						break
					prevpos = currpos + 1
					prev = currchar
				else:
					continue
			if res == None:
				yield 1
			else:
				yield min(res, prevpos)
cou = int(input())
ans = gift()
print(*ans, sep='\n')


cases = int(input())
for t in range(cases):
	(a, b, p) = list(map(int, input().split()))
	s = input()[::-1]
	d = {'A': a, 'B': b}
	c = len(s)
	prev = ''
	for i in s[1:]:
		if i != prev:
			p -= d[i]
		if p < 0:
			break
		else:
			c -= 1
		prev = i
	print(c)


t = int(input())
for _ in range(t):
	(a, b, p) = map(int, input().split())
	s = list(str(input()))
	n = len(s)
	s.reverse()
	A = []
	temp = s[1]
	cnt = 0
	for i in range(1, n):
		if s[i] != temp:
			if temp == 'A':
				A.append((a, i))
			else:
				A.append((b, i))
			temp = s[i]
		else:
			cnt += 1
	else:
		if temp == 'A':
			A.append((a, i + 1))
		else:
			A.append((b, i + 1))
	m = 0
	pre_i = 1
	for (c, i) in A:
		m += c
		if m > p:
			print(n - pre_i + 1)
			break
		else:
			pre_i = i
	else:
		print(1)


for _ in range(int(input())):
	(a, b, p) = map(int, input().split())
	s = input()
	n = len(s)
	prev = 'C'
	pay = 0
	sta = n
	li = [0]
	for i in range(n - 2, -1, -1):
		if s[i] != prev:
			prev = s[i]
			pay += b if prev == 'B' else a
		li.append(pay)
	li.reverse()
	for i in range(len(li)):
		if li[i] <= p:
			sta = i + 1
			break
	print(sta)


for _ in range(int(input())):
	(a, b, p) = map(int, input().split())
	x = input()
	cost = [a if x[0] == 'A' else b]
	pos = [0]
	for i in range(1, len(x)):
		if x[i - 1] != x[i]:
			cost.append(b if x[i] == 'B' else a)
			pos.append(i)
	if x[-1] != x[-2]:
		cost = cost[:len(cost) - 1]
		pos = pos[:len(pos) - 1]
	tot = sum(cost)
	done = False
	for i in range(len(cost)):
		if tot <= p:
			print(pos[i] + 1)
			done = True
			break
		else:
			tot -= cost[i]
	if not done:
		print(len(x))


t = int(input())
while t:
	t += -1
	(a, b, p) = map(int, input().split())
	s = input()
	l = []
	for i in s:
		l.append(i)
	cost = 0
	for i in range(len(l) - 1):
		if l[i + 1] != l[i]:
			if l[i] == 'A':
				cost += a
			else:
				cost += b
	if l[len(l) - 1] == l[len(l) - 2]:
		if l[len(l) - 1] == 'A':
			cost += a
		else:
			cost += b
	ind = -1
	for i in range(len(l) - 1):
		if cost <= p:
			ind = i
			break
		if l[i + 1] != l[i]:
			if l[i] == 'A':
				cost -= a
			else:
				cost -= b
	if ind == -1:
		print(len(l))
	else:
		print(ind + 1)


from bisect import bisect_left as bl
from bisect import bisect_right as br
import heapq
import math
from collections import *
from functools import reduce, cmp_to_key
import sys
input = sys.stdin.readline
M = mod = 10 ** 9 + 7

def factors(n):
	return sorted(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def inv_mod(n):
	return pow(n, mod - 2, mod)

def li():
	return [int(i) for i in input().rstrip('\n').split()]

def st():
	return input().rstrip('\n')

def val():
	return int(input().rstrip('\n'))

def li2():
	return [i for i in input().rstrip('\n').split(' ')]

def li3():
	return [int(i) for i in input().rstrip('\n')]
for _ in range(val()):
	(a, b, p) = li()
	s = st()
	n = len(s)
	ans = n - 1
	i = n - 2
	while i >= 0:
		temp = s[i]
		last = i
		while i >= 0 and s[i] == temp:
			i -= 1
		i += 1
		curr = a if s[i] == 'A' else b
		if p > curr:
			p -= curr
			ans = i
		elif p == curr:
			ans = i
			break
		else:
			break
		if i == 0:
			ans = 0
			break
		i -= 1
	print(ans + 1)


for _ in range(int(input())):
	(a, b, p) = map(int, input().split())
	cost = {'A': a, 'B': b}
	s = input()[::-1]
	l = 0
	c = ' '
	ans = len(s) - 1
	for i in range(1, len(s)):
		if s[i] == c:
			continue
		else:
			c = s[i]
			l += cost[c]
		if l > p:
			l -= cost[c]
			ans = i - 1
			break
	print(len(s) - ans)


import sys
input = sys.stdin.readline

def main():
	t = int(input())
	for _ in range(t):
		(A, B, P) = [int(x) for x in input().split()]
		S = input().strip()
		if P < A and P < B:
			print(len(S))
			continue
		c = S[0]
		cost = []
		if c == 'A':
			cost.append([1, A])
		else:
			cost.append([1, B])
		for (i, s) in enumerate(S):
			if s != c:
				c = s
				if c == 'A':
					cost.append([i + 1, A])
				else:
					cost.append([i + 1, B])
		if len(cost) == 1:
			if cost[0][1] > P:
				print(len(S))
			else:
				print(1)
			continue
		if cost[-1][0] == len(S):
			cost[-1][1] = 0
		else:
			cost.append([len(S), 0])
		for i in range(len(cost) - 2, -1, -1):
			cost[i][1] += cost[i + 1][1]
			if cost[i][1] > P:
				print(cost[i + 1][0])
				break
		else:
			print(1)
main()


t = int(input())
while t != 0:
	(a, b, p) = map(int, input().split())
	s = list(input())
	size = len(s)
	count = 0
	change = 0
	prev = s[0]
	price = []
	price.append(0)
	idx = []
	if p >= a or p >= b:
		if prev == 'A':
			price.append(a)
			idx.append(1)
		elif prev == 'B':
			price.append(b)
			idx.append(1)
		for i in range(1, size):
			if s[i] != prev and i != size - 1:
				if s[i] == 'A':
					price.append(a)
					idx.append(i + 1)
					change = change + 1
				else:
					price.append(b)
					idx.append(i + 1)
					change = change + 1
			prev = s[i]
		idx.append(size)
		ans = 1
		for k in range(len(price) - 1, -1, -1):
			count = count + price[k]
			ans = idx[k]
			if count > p:
				break
		print(ans)
	else:
		print(size)
	t = t - 1


t = int(input())
for _ in range(t):
	(a, b, p) = map(int, input().split())
	s = ' ' + input()
	(journey_cost, prev_change) = (0, None)
	for i in range(len(s) - 1, 0, -1):
		if s[i - 1] != s[i] and i != len(s) - 1:
			journey_cost += a if s[i] == 'A' else b
			if journey_cost > p:
				print(prev_change if prev_change is not None else len(s) - 1)
				break
			prev_change = i
	else:
		print(prev_change)


def solve(s, a, b, p):
	index = len(s)
	totalSum = 0
	while totalSum <= p and index > 0:
		index -= 1
		if index == len(s) - 1 or s[index - 1] != s[index]:
			totalSum += a if s[index - 1] == 'A' else b
	return index + 1
for case in range(int(input())):
	(a, b, p) = map(int, input().split())
	s = input()
	print(solve(s, a, b, p))


t = int(input())
for _ in range(t):
	(a, b, p) = map(int, input().split())
	s = input()
	n = len(s)
	if min(a, b) > p:
		print(n)
		continue
	now = n - 2
	bus = True
	tram = True
	flag = False
	ans = 0
	for i in range(n - 2, -1, -1):
		ans = i
		if flag == False:
			prev = i
			if s[i] == 'A' and p < a or (s[i] == 'B' and p < b):
				ans += 1
				break
			else:
				if s[i] == 'A':
					p -= a
				else:
					p -= b
				id = i
				flag = True
		elif s[i] == s[prev]:
			continue
		elif s[i] == 'A' and p < a or (s[i] == 'B' and p < b):
			ans += 1
			break
		else:
			prev = i
			if s[i] == 'A':
				p -= a
			else:
				p -= b
			flag = True
	print(ans + 1)


num_cases = int(input())
data_dictionary = {}
for case_number in range(1, num_cases + 1):
	line_data = input().split()
	data_dictionary[case_number] = {'a': int(line_data[0]), 'b': int(line_data[1]), 'p': int(line_data[2])}
	line_data = input()
	data_dictionary[case_number]['s'] = line_data

def split_to_sections(s):
	output_sequence = []
	output_i = []
	focus = 0
	start_index = focus
	current_type = s[start_index]
	while focus < len(s):
		if s[focus] != current_type or focus + 1 == len(s):
			output_sequence.append(s[start_index:focus + 1])
			output_i.append(start_index + 1)
			start_index = focus
			current_type = s[start_index]
		focus += 1
	return (output_sequence, output_i)

def compute_cost_list(section_list, a_cost, b_cost):
	output = []
	for section in section_list:
		if section[0] == 'A':
			cost = a_cost
		elif section[0] == 'B':
			cost = b_cost
		output.append(int(cost))
	return output

def find_minimum_i(cost_list, section_i, p, length_of_s):
	total_cost = 0
	number_steps_from_end = 0
	while number_steps_from_end < len(cost_list):
		current_step_cost = cost_list[-(number_steps_from_end + 1)]
		if total_cost + current_step_cost <= p:
			total_cost += current_step_cost
			number_steps_from_end += 1
		else:
			break
	if number_steps_from_end == 0:
		return length_of_s
	elif number_steps_from_end == len(cost_list):
		return 1
	else:
		return section_i[-number_steps_from_end]
for case in data_dictionary:
	a = data_dictionary[case]['a']
	b = data_dictionary[case]['b']
	p = data_dictionary[case]['p']
	s = data_dictionary[case]['s']
	(section_list, section_i) = split_to_sections(s)
	cost_list = compute_cost_list(section_list, a, b)
	min_i = find_minimum_i(cost_list, section_i, p, len(s))
	print(min_i)


t = int(input())
for _ in range(t):
	(a, b, p) = map(int, input().split())
	s = input()
	n = len(s)
	dp = [0] * n
	for i in range(n - 2, -1, -1):
		if i == n - 2:
			dp[i] = a if s[i] == 'A' else b
		elif s[i] == s[i + 1]:
			dp[i] = dp[i + 1]
		else:
			dp[i] = dp[i + 1] + (a if s[i] == 'A' else b)
	ans = -1
	for i in range(n):
		if dp[i] <= p:
			ans = i + 1
			break
	print(ans)


import sys
input = sys.stdin.readline
Q = int(input())
Query = []
for _ in range(Q):
	(a, b, p) = map(int, input().split())
	S = list(input().rstrip())
	Query.append((a, b, p, S))
for (a, b, p, S) in Query:
	L = len(S)
	S.pop()
	while S:
		s = S[-1]
		if s == 'A':
			t = a
		else:
			t = b
		if t > p:
			break
		p -= t
		while S and S[-1] == s:
			S.pop()
	print(len(S) + 1)


t = int(input())
for _ in range(t):
	(a, b, p) = list(map(int, input().split()))
	s = input()
	i = len(s)
	sum1 = 0
	while sum1 <= p and i > 0:
		i = i - 1
		if i == len(s) - 1 or s[i - 1] != s[i]:
			if s[i - 1] == 'A':
				sum1 += a
			else:
				sum1 += b
		else:
			pass
	print(i + 1)


import re
import bisect
t = int(input())
for t1 in range(t):
	line = input()
	price = dict()
	(price['A'], price['B'], budget) = (int(x) for x in line.split())
	line = input()[:-1]
	line_len = len(line) + 1
	indices = [1]
	for c in range(1, len(line)):
		if line[c - 1] != line[c]:
			indices.append(c + 1)
	line = re.sub('A+', 'A', line)
	line = re.sub('B+', 'B', line)
	costs = [price[x] for x in line][::-1]
	for x in range(1, len(costs)):
		costs[x] = costs[x] + costs[x - 1]
	z = bisect.bisect_right(costs, budget)
	if z == 0:
		print(line_len)
	else:
		print(indices[-z])


import sys, math, bisect
from random import randint
inf = float('inf')
mod = 10 ** 9 + 7

def lcm(a, b):
	return int(a / math.gcd(a, b) * b)

def gcd(a, b):
	return int(math.gcd(a, b))

def tobinary(n):
	return bin(n)[2:]

def binarySearch(a, x):
	i = bisect.bisect_left(a, x)
	if i != len(a) and a[i] == x:
		return i
	else:
		return -1

def lowerBound(a, x):
	i = bisect.bisect_left(a, x)
	if i:
		return i - 1
	else:
		return -1

def upperBound(a, x):
	i = bisect.bisect_right(a, x)
	if i != len(a) + 1 and a[i - 1] == x:
		return i - 1
	else:
		return -1

def primesInRange(n):
	ans = []
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	for p in range(2, n + 1):
		if prime[p]:
			ans.append(p)
	return ans

def primeFactors(n):
	factors = []
	while n % 2 == 0:
		factors.append(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			factors.append(i)
			n = n // i
	if n > 2:
		factors.append(n)
	return factors

def isPrime(n, k=5):
	if n < 2:
		return True
	for i in range(0, k):
		a = randint(1, n - 1)
		if pow(a, n - 1, n) != 1:
			return False
	return True
from collections import deque, defaultdict, Counter
import heapq, string
for _ in range(int(input())):
	(b, a, p) = map(int, input().split())
	s = input()
	n = len(s)
	if len(s) == 1:
		print(1)
		continue
	l = 0
	ans = len(s)
	for i in range(n - 2, -1, -1):
		if i == 0 or s[i] != s[i - 1]:
			if s[i] == 'A':
				l += b
			else:
				l += a
			if l <= p:
				ans = i + 1
	print(ans)


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools
from collections import deque, defaultdict, OrderedDict
import collections

def main():
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	mod = 998244353
	for _ in range(ri()):
		(a, b, p) = ria()
		s = rs()
		c = 0
		t = 0
		k = 1
		cost = []
		dist = []
		for i in range(1, len(s)):
			if s[i] != s[i - 1]:
				dist.append(k)
				k = 0
				t = i
				if s[i - 1] == 'A':
					c += a
					cost.append(a)
				else:
					c += b
					cost.append(b)
			k += 1
		if t != len(s) - 1:
			if s[t] == 'A':
				c += a
				cost.append(a)
			else:
				c += b
				cost.append(b)
		dist.append(len(s) - t)
		dist[-1] -= 1
		ans = 1
		for i in range(len(cost)):
			if c > p:
				ans += dist[i]
				c -= cost[i]
			else:
				break
		wi(ans)
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

	def flush(self):
		os.write(self._fd, self.buffer.getvalue())
		(self.buffer.truncate(0), self.buffer.seek(0))

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


from sys import stdin
out = []
for _ in range(int(input())):
	(a, b, rem) = map(int, stdin.readline().split())
	s = stdin.readline().strip()
	ix = len(s) - 1
	(ans, cost) = (ix + 1, 0)
	if s[-1] != s[-2]:
		ix -= 1
	while ix > -1:
		lst = s[ix]
		while ix > -1 and s[ix] == lst:
			ix -= 1
		cost += a if lst == 'A' else b
		if cost > rem:
			break
		ans = ix + 2
	out.append(ans)
print(*out, sep='\n')


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def li():
	return list(mi())

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
import math
mod = 10 ** 9
mod += 7

def main():
	for i in range(ii()):
		(a, b, p) = mi()
		s = si()
		f = 0
		r = 0
		pre = 'X'
		i = len(s) - 2
		while i >= 0 and f == 0:
			if s[i] != pre:
				pre = s[i]
				if s[i] == 'A':
					r = a
				else:
					r = b
				p -= r
				if p < 0:
					print(i + 2)
					f = 1
			i -= 1
		if f == 0:
			print(1)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())
for _ in range(t):
	(a, b, p) = map(int, input().split())
	s = input()
	factor = 10 ** 9 + 7
	l = []
	prev = s[0]
	if prev == 'A':
		l.append(factor)
	else:
		l.append(1)
	for i in range(1, len(s) - 1):
		if s[i] != prev:
			if s[i] == 'A':
				l.append((i + 1) * factor)
			else:
				l.append(i + 1)
			prev = s[i]
	ans = -1
	left = 0
	right = len(l) - 1
	while left <= right:
		mid = left + (right - left) // 2
		if l[mid] % factor == 0:
			if (len(l) - mid) % 2 == 1:
				total = (len(l) - mid + 1) // 2 * a + (len(l) - mid - 1) // 2 * b
			else:
				total = (len(l) - mid) // 2 * (a + b)
		elif (len(l) - mid) % 2 == 1:
			total = (len(l) - mid + 1) // 2 * b + (len(l) - mid - 1) // 2 * a
		else:
			total = (len(l) - mid) // 2 * (a + b)
		if total <= p:
			if l[mid] % factor == 0:
				ans = l[mid] // factor
			else:
				ans = l[mid]
			right = mid - 1
		else:
			left = mid + 1
	if ans == -1:
		ans = len(s)
	print(ans)


for _ in range(int(input())):
	(a, b, p) = map(int, input().split())
	s = input()
	prev = 'X'
	flag = 0
	money = [0] * len(s)
	mm = 0
	for i in range(len(s) - 2, -1, -1):
		if s[i] == prev:
			flag = 1
			money[i] = mm
		elif s[i] == 'A':
			flag = 1
			prev = 'A'
			mm += a
			money[i] = mm
		elif s[i] == 'B':
			flag = 1
			prev = 'B'
			mm += b
			money[i] = mm
	flag = 0
	for i in range(len(money)):
		if money[i] <= p:
			flag = 1
			break
	if flag == 1:
		print(i + 1)
	else:
		print(len(s))


t = int(input())
for case in range(t):
	(a, b, p) = map(int, input().split(' '))
	s = input()
	i = len(s) - 1
	if s[i - 1] == 'A':
		cost = a
	elif s[i - 1] == 'B':
		cost = b
	if cost > p:
		print(i + 1)
		continue
	i -= 1
	while i >= 1:
		if s[i - 1] == 'A' and s[i] == 'B':
			if cost + a > p:
				break
			cost += a
		elif s[i - 1] == 'B' and s[i] == 'A':
			if cost + b > p:
				break
			cost += b
		i -= 1
	print(i + 1)


from sys import stdin, stdout, setrecursionlimit

class Tail_Recursion_Optimization:

	def __init__(self, RECURSION_LIMIT, STACK_SIZE):
		setrecursionlimit(RECURSION_LIMIT)
		threading.stack_size(STACK_SIZE)
		return None

class SOLVE:

	def solve(self):
		R = stdin.readline
		W = stdout.write
		ans = []
		for i in range(int(R())):
			(a, b, p) = [int(x) for x in R().split()]
			s = R()
			l = len(s) - 1
			total = 0
			ind = []
			for j in range(l):
				if j == 0 or (j < l - 1 and s[j] != s[j - 1]):
					total += [a, b][s[j] == 'B']
					ind.append(j)
			flg = 1
			for j in range(len(ind)):
				if total <= p:
					ans.append(str(ind[j] + 1))
					flg = 0
					break
				total -= [a, b][s[ind[j]] == 'B']
			if flg:
				ans.append(str(l))
		W('\n'.join(ans))
		return 0

def main():
	s = SOLVE()
	s.solve()
main()


t = int(input())
for i in range(t):
	dic = {}
	dic[0] = 0
	datos = list(map(int, input().split(' ')))
	s = input()
	actual = s[0]
	total = 0
	indi = 0
	for i in range(len(s)):
		if actual != s[i] and i < len(s) - 1:
			if actual == 'A':
				total += datos[0]
			else:
				total += datos[1]
			actual = s[i]
			dic[i] = total
	if actual == 'A':
		total += datos[0]
	else:
		total += datos[1]
	dic[len(s) - 1] = total
	for (key, value) in dic.items():
		if total - value <= datos[2]:
			print(key + 1)
			break


from math import *

def check(a, b, p, s, x):
	ps = s[x]
	ans = 0
	for i in range(x, len(s)):
		if ps == s[i]:
			pass
		else:
			if ps == 'A':
				ans += a
			else:
				ans += b
			if s[i] == 'E':
				break
			ps = s[i]
	return ans <= p
zzz = int(input())
for zz in range(zzz):
	(a, b, p) = map(int, input().split())
	s = input()
	s = list(s)
	s[-1] = 'E'
	s = ''.join(s)
	lb = 0
	ub = len(s) + 1
	while lb + 1 < ub:
		tx = (lb + ub) // 2
		dx = (ub - lb) // 2
		if check(a, b, p, s, tx):
			ub -= dx
		else:
			lb += dx
	x = (lb + ub) // 2
	for i in range(4):
		if x > 0 and check(a, b, p, s, x - 1):
			x -= 1
		elif x <= len(s) and (not check(a, b, p, s, x)):
			x += 1
	print(min(x + 1, len(s)))


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def msi():
	return map(str, input().strip().split(' '))

def li():
	return list(mi())

def dmain():
	sys.setrecursionlimit(1000000)
	threading.stack_size(1024000)
	thread = threading.Thread(target=main)
	thread.start()
import sys
input = sys.stdin.readline
scanner = lambda : int(input())
string = lambda : input().rstrip()
get_list = lambda : list(read())
read = lambda : map(int, input().split())
get_float = lambda : map(float, input().split())

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def factorial(x, m):
	val = 1
	while x > 0:
		val = val * x % m
		x -= 1
	return val

def fact(x):
	val = 1
	while x > 0:
		val *= x
		x -= 1
	return val

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	return a * b // math.gcd(a, b)

def is_integer(n):
	return math.ceil(n) == math.floor(n)

def nCr(n, k):
	if k > n:
		return 0
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	if y == 0:
		return 1
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	(prime[0], prime[1]) = (False, False)
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def phi(n):
	result = n
	p = 2
	while p * p <= n:
		if n % p == 0:
			while n % p == 0:
				n = n // p
			result = result * (1.0 - 1.0 / float(p))
		p = p + 1
	if n > 1:
		result = result * (1.0 - 1.0 / float(n))
	return int(result)

def is_prime(n):
	if n == 0:
		return False
	if n == 1:
		return True
	for i in range(2, int(n ** (1 / 2)) + 1):
		if not n % i:
			return False
	return True

def next_prime(n, primes):
	while primes[n] != True:
		n += 1
	return n
MAXN = int(100000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i
spf = [0 for i in range(MAXN)]

def factoriazation(x):
	res = []
	for i in range(2, int(x ** 0.5) + 1):
		while x % i == 0:
			res.append(i)
			x //= i
	if x != 1:
		res.append(x)
	return res

def factors(n):
	res = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			res.append(i)
			res.append(n // i)
	return list(set(res))

def int_array():
	return list(map(int, input().strip().split()))

def float_array():
	return list(map(float, input().strip().split()))

def str_array():
	return input().strip().split()

def binary_search(low, high, w, h, n):
	while low < high:
		mid = low + (high - low) // 2
		if check(mid, w, h, n):
			low = mid + 1
		else:
			high = mid
	return low

def check(moves, n):
	val = (moves + 1) // 2
	rem = moves - val
	sol = (val + 1) * (rem + 1)
	return sol < n

def sortSecond(val):
	return val[1]
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
alphs = 'abcdefghijklmnopqrstuvwxyz'
from itertools import permutations
import math
import bisect as bis
import random
import sys
import collections as collect
import functools as fnt
from decimal import Decimal

def solve():
	(a, b, p) = read()
	s = string()
	n = len(s)
	if s[-2] == 'A':
		flag = 0
	else:
		flag = 1
	ans = 0
	val = n
	for i in range(n - 2, -1, -1):
		if s[i] == 'A' and flag == 0:
			ans += a
			if ans <= p:
				val = i + 1
			flag = 1
		elif s[i] == 'B' and flag == 1:
			ans += b
			if ans <= p:
				val = i + 1
			flag = 0
		if ans > p:
			break
		elif ans <= p:
			val = i + 1
	print(val)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
t = scanner()
for i in range(t):
	solve()


n = int(input())
for _ in range(n):
	(a, b, p) = map(int, input().split())
	s = input()
	soma = 0
	res = 0
	if s[0] == 'A':
		soma = a
	else:
		soma = b
	for i in range(1, len(s) - 1):
		if s[i] == 'A' and s[i] != s[i - 1]:
			soma += a
		if s[i] == 'B' and s[i] != s[i - 1]:
			soma += b
	if soma <= p:
		print(1)
		continue
	else:
		if s[0] == 'A':
			soma -= a
		else:
			soma -= b
		sim = 0
		for i in range(1, len(s) - 1):
			if s[i] == 'A' and s[i] != s[i - 1]:
				if soma <= p:
					res = i + 1
					sim = 1
					break
				soma -= a
			if s[i] == 'B' and s[i] != s[i - 1]:
				if soma <= p:
					res = i + 1
					sim = 1
					break
				soma -= b
			if sim:
				break
	if res == 0:
		print(len(s))
	else:
		print(res)


for _ in range(int(input())):
	(a, b, p) = map(int, input().split())
	s = input()[:-1] + 'X'
	n = len(s)
	l = [None] * n
	l[-1] = 0
	for i in range(n - 2, -1, -1):
		l[i] = l[i + 1]
		if s[i + 1] != s[i]:
			if s[i] == 'A':
				l[i] += a
			if s[i] == 'B':
				l[i] += b
	if l[0] < p:
		print(1)
		continue
	if l[-2] > p:
		print(n)
		continue
	for i in range(n - 1, -1, -1):
		if l[i] > p:
			print(i + 2)
			break
	else:
		print(1)


for _ in range(int(input())):
	(a, b, p) = map(int, input().split(' '))
	S = input()
	price = []
	if S[0] == 'A':
		t = 0
	else:
		t = 1
	for j in range(len(S)):
		if t == 0:
			if j == len(S) - 1:
				price.append((a, j))
			elif S[j] != 'A':
				price.append((a, j))
				t = 1
		elif j == len(S) - 1:
			price.append((b, j))
		elif S[j] != 'B':
			price.append((b, j))
			t = 0
	tot = 0
	for i in range(len(price) - 1, -1, -1):
		tot += price[i][0]
		if tot > p:
			print(price[i][1] + 1)
			break
		elif i == 0:
			print(1)
			break


t = int(input())
for _ in range(t):
	(a, b, p) = map(int, input().split())
	sl = list(input())
	before = ''
	for (idx, i) in enumerate(sl[::-1][1:]):
		cost = a if i == 'A' else b
		if before == i:
			continue
		if cost > p:
			break
		else:
			before = i
			p -= cost
	else:
		print(1)
		continue
	print(len(sl) - idx)


for _ in range(int(input())):
	(a, b, p) = list(map(int, input().split()))
	st = input()
	pos = []
	amount = []
	prev = None
	for i in range(len(st)):
		if st[i] != prev:
			pos.append(i)
			prev = st[i]
	if pos[-1] == len(st) - 1:
		pos.pop()
	prev_am = 0
	for k in range(-1, -len(pos) - 1, -1):
		if st[pos[k]] == 'B':
			amount.append(prev_am + b)
			prev_am += b
		else:
			amount.append(prev_am + a)
			prev_am += a
	amount.reverse()
	for j in range(len(amount)):
		if amount[j] <= p:
			print(pos[j] + 1)
			break
	else:
		print(len(st))


def solve(a, b, x, s):
	s = 'x' + s
	last_station = len(s) - 1
	for i in reversed(range(len(s))):
		if s[i] != s[i - 1] and i != len(s) - 1:
			if s[i] == 'B':
				x -= b
			elif s[i] == 'A':
				x -= a
			if x >= 0:
				last_station = i
		if x <= 0:
			return last_station
	return 1
n = int(input())
for _ in range(n):
	(a, b, x) = list(map(int, input().split()))
	s = input()
	print(solve(a, b, x, s))


t = int(input())
for _ in range(t):
	(a, b, p) = map(int, input().split())
	string = input()
	dp = []
	money = []
	n = len(string)
	for i in range(1, n):
		if string[i] != string[i - 1]:
			dp.append(i)
			if string[i - 1] == 'A':
				money.append(a)
			else:
				money.append(b)
	if string[n - 1] == string[n - 2]:
		if len(dp):
			dp.append(dp[-1] + 1)
		else:
			dp.append(n - 1)
		if string[n - 1] == 'A':
			money.append(a)
		else:
			money.append(b)
	for i in range(len(money) - 2, -1, -1):
		money[i] += money[i + 1]
	check = False
	for i in range(len(money)):
		if p >= money[i]:
			if i == 0:
				print(1)
			else:
				print(dp[i - 1] + 1)
			check = True
			break
	if not check:
		print(n)


t = int(input())
while t:
	t -= 1
	(a, b, p) = map(int, input().split())
	d = {'A': a, 'B': b}
	s = input()
	n = len(s)
	ans = n - 2
	prev = s[-2]
	while ans >= 0:
		val = s[ans]
		if d[val] <= p:
			p -= d[val]
			while ans >= 0 and s[ans] == val:
				ans -= 1
		else:
			break
	print(ans + 2)


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	s = input()
	s = s[:len(s) - 1]
	i = len(s) - 1
	z = 0
	while i >= 0 and c > 0:
		if s[i] == 'A':
			z = a
			if c >= z:
				c -= z
			else:
				break
			i -= 1
			while i >= 0 and s[i] == 'A':
				i -= 1
		if i >= 0 and s[i] == 'B':
			z = b
			if c >= z:
				c -= z
			else:
				break
			i -= 1
			while i >= 0 and s[i] == 'B':
				i -= 1
	print(i + 2)


import sys, collections, math, itertools, random, bisect
INF = sys.maxsize

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def input():
	return sys.stdin.readline().strip()
mod = int(1000000000.0 + 7)
for _ in range(int(input())):
	(a, b, p) = get_ints()
	s = input()
	sz = len(s)
	sum = 0
	while sum <= p and sz > 0:
		sz -= 1
		if sz == len(s) - 1 or s[sz - 1] != s[sz]:
			if s[sz - 1] == 'A':
				sum += a
			else:
				sum += b
	print(sz + 1)


for _ in range(int(input())):
	(a, b, p) = map(int, input().split())
	s = input()
	n = len(s)
	s = s[::-1][1:]
	l = s[0]
	if s[0] == 'A':
		p -= a
	else:
		p -= b
	if p < 0:
		print(n)
		continue
	fl = 1
	for i in range(len(s)):
		if p >= 0:
			if l != s[i]:
				if s[i] == 'A':
					p -= a
					l = s[i]
				else:
					p -= b
					l = s[i]
		else:
			break
		if p < 0:
			print(n - i)
			fl = 0
			continue
	if fl == 1:
		print(1)


t = int(input())

def find(a, b, p, s):
	if p < a and p < b:
		print(len(s))
		return
	cash = 0
	stopInd = -1
	count = 0
	t = s[0:len(s) - 1][::-1]
	for (ind, k) in enumerate(t):
		if k == 'A':
			if ind == 0:
				if k == s[-1]:
					if cash + a <= p:
						cash += a
						stopInd = ind
						continue
					else:
						break
				elif cash + a <= p:
					cash += a
					stopInd = ind
					continue
				else:
					print(len(s))
					return
			else:
				if k == t[ind - 1]:
					stopInd = ind
					if ind == len(s) - 2:
						print(1)
						return
					continue
				if cash + a <= p:
					cash += a
					stopInd = ind
				else:
					cash += a
					stopInd = ind
					break
		if k == 'B':
			if ind == 0:
				if k == s[-1]:
					if cash + b <= p:
						cash += b
						stopInd = ind
						continue
					else:
						break
				elif cash + b <= p:
					cash += b
					stopInd = ind
					continue
				else:
					print(len(s))
					return
			else:
				if k == t[ind - 1]:
					stopInd = ind
					if ind == len(s) - 2:
						print(1)
						return
					continue
				if cash + b <= p:
					cash += b
					stopInd = ind
				else:
					cash += b
					stopInd = ind
					break
	if stopInd == 0:
		print(len(s) - 1)
	elif stopInd == -1:
		print(len(s))
	elif cash <= p:
		print(1)
	else:
		print(len(s) - stopInd)
for i in range(t):
	(a, b, p) = map(int, input().split())
	s = input()
	find(a, b, p, s)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from functools import cmp_to_key
from heapq import *
from math import gcd, factorial, floor, ceil
from copy import deepcopy
from collections import deque
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for pp in range(t):
		solve(pp)

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def google(p):
	print('Case #' + str(p) + ': ', end='')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True
inf = pow(10, 20)
mod = 10 ** 9 + 7

def solve(case):
	(a, b, p) = sep()
	s = inp()
	n = len(s)
	aa = []
	for i in range(n):
		if s[i] == 'A':
			aa.append(1)
		else:
			aa.append(2)
	pre = [0] * (n + 1)
	pre[0] = a if aa[0] == 1 else b
	for i in range(1, n):
		if aa[i] == aa[i - 1]:
			pre[i] = pre[i - 1]
		else:
			if i == n - 1:
				pre[i] = pre[i - 1]
				continue
			pre[i] = pre[i - 1] + (a if aa[i] == 1 else b)
	ans = n
	for i in range(n):
		if pre[n - 1] - pre[i] + (a if aa[i] == 1 else b) <= p:
			ans = min(ans, i + 1)
	print(ans)
testcase(int(inp()))


for _ in range(int(input())):
	(b, t, p) = map(int, input().split())
	s = input()
	n = len(s)
	cost = [0] * n
	for i in range(n - 2, -1, -1):
		cost[i] = cost[i + 1]
		if i == n - 2 or s[i] != s[i + 1]:
			if s[i] == 'A':
				cost[i] += b
			else:
				cost[i] += t
	for i in range(n):
		if cost[i] <= p:
			print(i + 1)
			break


T = int(input().strip())
debug = False
for t in range(T):
	(a, b, p) = map(int, input().split())
	S = str(input().strip())
	l = len(S)
	total = []
	sumTotal = 0
	curr = ''
	for i in range(l - 1):
		c = S[i]
		if c != curr:
			if c == 'A':
				total.append(a)
				sumTotal += a
			else:
				total.append(b)
				sumTotal += b
			curr = c
		else:
			total.append(0)
	N = 1
	if p >= sumTotal:
		print(N)
	else:
		for i in range(len(total)):
			if total[i] != 0:
				if p >= sumTotal:
					break
				sumTotal -= total[i]
			else:
				pass
			N += 1
		print(N)


t = int(input())
vec = []
for i in range(t):
	(a, b, p) = [int(j) for j in input().split(' ')]
	s = input()
	marker_prev = s[-1]
	paid = 0
	pos = len(s)
	for marker_now in s[-2::-1]:
		if marker_now != marker_prev:
			paid = 0
		if paid == 0:
			if marker_now == 'A':
				g = a
			else:
				g = b
			if p >= g:
				p -= g
				paid = 1
			else:
				break
		pos -= 1
		marker_prev = marker_now
	vec.append(pos)
for j in vec:
	print(j)


t = int(input())
for _ in range(t):
	(a, b, p) = list(map(int, input().split()))
	s = input()
	price = {'A': a, 'B': b}
	route = []
	prev = None
	idx = 1
	start = 0
	for ch in s:
		if prev == None:
			prev = ch
			start = idx
			idx += 1
			continue
		if prev != ch:
			route.append([start, price[prev]])
			prev = ch
			start = idx
		idx += 1
	if start < len(s):
		route.append([start, price[prev]])
	route.reverse()
	cost = 0
	result = len(s)
	prev = None
	for item in route:
		cost += item[1]
		if cost > p:
			break
		prev = item
	if prev != None:
		result = prev[0]
	print(result)


for _ in range(int(input())):
	(*a, c) = map(int, input().split())
	str = input()
	i = len(str) - 2
	j = str[-2] == 'B'
	while i >= 0 and c - a[j] >= 0:
		c -= a[j]
		j ^= 1
		i = str.rfind('AB'[j], 0, i)
	print(i + 2)


import os
import heapq
import sys, threading
import math as mt
import operator
from copy import copy
from collections import defaultdict, deque
from io import BytesIO, IOBase
sys.setrecursionlimit(2 * 10 ** 5)

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

def inpt():
	return [int(k) for k in input().split()]

def main():
	for _ in range(int(input())):
		(a, b, p) = inpt()
		s = input()
		n = len(s)
		sm = 0
		ans = []
		prev = 'N'
		for i in range(n - 1):
			if s[i] != prev:
				if s[i] == 'A':
					sm += a
					ans.append((i, a))
				else:
					sm += b
					ans.append((i, b))
				prev = s[i]
		ok = False
		for (i, j) in ans:
			if sm <= p:
				ok = True
				print(i + 1)
				break
			sm -= j
		if not ok:
			print(n)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys

def input():
	return sys.stdin.readline().rstrip('\r\n')
t = int(input())
while t:
	t -= 1
	(a, b, p) = map(int, input().split())
	s = input()
	n = len(s)
	change = []
	cur = s[0]
	for i in range(1, n):
		if s[i] == cur:
			continue
		else:
			cur = s[i]
			change.append(i)
	if s[n - 2] == s[n - 1]:
		change.append(n)
	m = len(change)
	cur = s[0]
	if s[0] == 'A':
		tot = a * ((m + 1) // 2) + b * (m - (m + 1) // 2)
	else:
		tot = b * ((m + 1) // 2) + a * (m - (m + 1) // 2)
	ans = 0
	if p >= tot:
		print(1)
		continue
	cur = s[0]
	for i in range(1, n):
		if s[i] != cur:
			tot -= a if cur == 'A' else b
			cur = s[i]
			if tot <= p:
				print(i + 1)
				break
	else:
		print(n)


for _ in range(int(input())):
	(a, b, p) = map(int, input().split())
	s = input()
	if len(s) <= 1:
		print(0)
	else:
		d = [0] * len(s)
		if s[0] == 'A':
			d[0] = a
			temp = a
		else:
			d[0] = b
			temp = b
	for i in range(1, len(s)):
		if s[i] == s[i - 1]:
			d[i] = temp
		else:
			d[i] = temp
			if s[i] == 'A':
				temp += a
			else:
				temp += b
	temp = d[len(d) - 1]
	if p >= d[len(d) - 1]:
		print(1)
	else:
		for i in range(len(d)):
			d[i] = temp - d[i]
		for i in range(len(d)):
			if i != len(d) - 1:
				if p >= d[i] and d[i] != d[i + 1]:
					break
			else:
				break
		print(i + 1)


t = int(input())
cost = []
road = []
final = []
for i in range(0, t):
	str1 = input()
	str2 = input()
	cost.append(str1.split())
	road.append(list(str2))
for j in range(0, t):
	A_cost = int(cost[j][0])
	B_cost = int(cost[j][1])
	money = int(cost[j][2])
	path = road[j]
	k = len(path) - 2
	pos = path[k]
	if pos == 'A':
		remain = A_cost
	else:
		remain = B_cost
	if money < remain:
		final.append(k + 2)
	else:
		while k > 0:
			if pos != path[k - 1]:
				pos = path[k - 1]
				k = k - 1
				if pos == 'A':
					remain += A_cost
				else:
					remain += B_cost
				if money < remain:
					final.append(k + 2)
					break
			else:
				k = k - 1
	if k == 0 and money >= remain:
		final.append(1)
for no in final:
	print(no)


t = int(input())
while t:
	t = t - 1
	(a, b, p) = [int(s) for s in input().split()]
	s = [i for i in input()]
	n = len(s)
	payable_station_name = []
	payable_station_id = []
	cost_has_to_paid = []
	x = s[n - 2]
	payable_station_name.append(s[n - 1])
	payable_station_id.append(n - 1)
	for i in range(n - 2, -1, -1):
		if s[i] != x:
			payable_station_name.append(x)
			payable_station_id.append(i + 1)
			x = s[i]
	payable_station_id.append(0)
	payable_station_name.append(s[0])
	station_at_which_reach = 0
	for i in range(1, len(payable_station_name)):
		station = payable_station_name[i]
		if station == 'A':
			if p >= a:
				p = p - a
			else:
				station_at_which_reach = payable_station_id[i - 1]
				break
		elif station == 'B':
			if p >= b:
				p = p - b
			else:
				station_at_which_reach = payable_station_id[i - 1]
				break
	print(station_at_which_reach + 1)


for _ in range(int(input())):
	(a, b, p) = list(map(int, input().split()))
	st = input()
	pos = []
	amount = []
	c = 0
	prev = None
	ind = len(st)
	for i in range(-2, -len(st) - 1, -1):
		if st[i] != prev:
			if st[i] == 'A':
				if c + a > p:
					break
				else:
					c += a
				prev = 'A'
			elif c + b > p:
				break
			else:
				c += b
				prev = 'B'
		ind -= 1
	print(ind)


from bisect import bisect_left as bl, bisect_right as br, insort
import sys
import heapq
from math import *
from collections import defaultdict as dd, deque

def data():
	return sys.stdin.readline().strip()

def mdata():
	return map(int, data().split())
for i in range(int(input())):
	(a, b, p) = mdata()
	s = input()
	if s[-2] == 'B':
		k = 'A'
	else:
		k = 'B'
	ans = 0
	n = len(s)
	ind = n - 1
	d = {'A': a, 'B': b}
	flag = True
	for i in range(n - 2, -1, -1):
		if s[i] != k:
			k = s[i]
			if ans + d[k] > p:
				ind = i
				flag = False
				break
			else:
				ans += d[k]
				ind = i
	if flag == True:
		ind = -1
	print(ind + 2)


def foo():
	(a, b, petyaM) = list(map(int, input().split()))
	s = input()
	current = 'N'
	money = [0] * len(s)
	j = len(s) - 2
	for i in reversed(s[:-1]):
		if i != current:
			if i == 'A':
				money[j] += a
			else:
				money[j] += b
			current = i
		money[j] += money[j + 1]
		j -= 1
	walk = len(s)
	for i in range(len(money) - 1, -1, -1):
		if petyaM >= money[i]:
			walk = i + 1
	if petyaM > money[0]:
		walk = 1
	print(walk)
t = int(input())
for i in range(t):
	foo()


from collections import defaultdict
import bisect
from itertools import accumulate
import os
import sys
import math
from decimal import *
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def good(mid, s, a, b, p):
	count = 0
	if s[mid] == 'A':
		count = a
	else:
		count = b
	for i in range(mid + 1, len(s) - 1):
		if s[i] != s[i - 1]:
			if s[i] == 'A':
				count += a
			else:
				count += b
	if count <= p:
		return True
	else:
		return False
for _ in range(int(input())):
	(a, b, p) = map(int, input().split())
	s = input()
	count = 0
	l = 0
	r = len(s) - 1
	ans = len(s) - 1
	while l <= r:
		mid = (l + r) // 2
		if good(mid, s, a, b, p) == True:
			ans = mid
			r = mid - 1
		else:
			l = mid + 1
	print(ans + 1)


t = int(input())
for _ in range(t):
	(a, b, p) = list(map(int, input().split()))
	s = input().strip()
	m = {'A': a, 'B': b}
	temp = {(len(s) - 1, m[s[-2]])}
	for i in reversed(range(len(s) - 1)):
		if s[i] != s[i + 1]:
			temp.add((i + 1, m[s[i]]))
	temp = list(temp)
	temp.sort(reverse=True)
	flag = True
	for e in temp:
		if p < e[1]:
			print(e[0] + 1)
			flag = False
			break
		else:
			p -= e[1]
	if flag:
		print(1)


def main():
	for _ in range(int(input())):
		(a, b, p) = map(int, input().split())
		s = input()
		s = s[::-1]
		ans = 1
		cur = s[1]
		pay = {'A': a, 'B': b}
		stop = 1
		p -= pay[cur]
		if p < 0:
			print(len(s))
			continue
		flag = False
		STOP = False
		for i in range(2, len(s)):
			if s[i] != cur:
				if flag:
					stop = i - 1
					STOP = True
					break
				p -= pay[s[i]]
				cur = s[i]
				if p < 0:
					stop = i - 1
					break
				if p == 0:
					flag = True
		if p >= 0 and (not STOP):
			print(1)
			continue
		ans = len(s) - stop
		print(ans)
main()


t = int(input())
e = []
for i in range(t):
	(a, b, p) = input().split()
	a = int(a)
	b = int(b)
	p = int(p)
	s = input()
	n = len(s)
	c = 0
	o = 0
	a1 = 0
	b1 = 0
	q = s[0]
	for j in range(n):
		if s[j] == 'A' and q == 'B':
			b1 += 1
			q = 'A'
		elif s[j] == 'B' and q == 'A':
			a1 += 1
			q = 'B'
		elif q == s[j] and j == n - 1:
			if q == 'A':
				a1 += 1
			else:
				b1 += 1
	c = a1 * a + b1 * b
	r = c - p
	if r < 1:
		e.insert(i, 1)
	else:
		a1 = 0
		b1 = 0
		q = s[0]
		for j in range(n):
			if s[j] == 'A' and q == 'B':
				b1 += 1
				q = 'A'
			elif s[j] == 'B' and q == 'A':
				a1 += 1
				q = 'B'
			elif q == s[j] and j == n - 1:
				if q == 'A':
					a1 += 1
				else:
					b1 += 1
			o = a1 * a + b1 * b
			if r <= o:
				e.insert(i, j + 1)
				break
			elif j == n - 1 and r > o:
				e.insert(i, j + 1)
print(*e, sep='\n')


for _ in range(int(input())):
	(a, b, p) = map(int, input().split())
	s = input()
	n = len(s)
	cost = 0
	i = 0
	while i < n - 1:
		k = s[i]
		while s[i] == k:
			i += 1
			if i == n - 1:
				break
		if k == 'A':
			cost += a
		else:
			cost += b
	i = 0
	while cost > p and i < n - 1:
		if s[i] == 'A':
			cost -= a
			while s[i] == 'A':
				i += 1
				if i == n - 1:
					break
		else:
			cost -= b
			while s[i] == 'B':
				i += 1
				if i == n - 1:
					break
	print(i + 1)


a = int(input())
for i in range(a):
	(a, b, p) = map(int, input().split())
	s = input()
	glag = 0
	flag = 0
	if s[0] == 'A':
		flag = 0
	else:
		flag = 1
	cost = []
	if flag == 1:
		cost.append(b)
	else:
		cost.append(a)
	for i in range(1, len(s)):
		if s[i] != s[i - 1] and i != len(s) - 1:
			if s[i] == 'A':
				cost.append(cost[-1] + a)
			else:
				cost.append(cost[-1] + b)
	cost = list(set(cost))
	cost.sort(reverse=True)
	ans = [cost[0]]
	for i in range(1, len(s) - 1):
		if s[i] == s[i - 1]:
			ans.append(ans[-1])
		elif s[i] == 'B':
			ans.append(ans[-1] - a)
		else:
			ans.append(ans[-1] - b)
	for i in range(len(ans)):
		if p >= ans[i]:
			print(i + 1)
			glag = 1
			break
	if glag == 0:
		print(len(s))


for t in range(int(input())):
	(a, b, p) = map(int, input().split())
	s = '_' + input()
	n = len(s) - 1
	i = n - 1
	cost = [a, b]
	while i > 0:
		price = cost[ord(s[i]) - ord('A')]
		if price <= p:
			p -= price
		else:
			break
		j = i
		while s[j] == s[i]:
			j -= 1
		i = j
	print(i + 1)


import sys
t = int(sys.stdin.readline())
ans_arr = []
for i in range(t):
	[a, b, p] = [int(x) for x in sys.stdin.readline().split()]
	s = sys.stdin.readline().strip()
	ans = 0
	n = len(s)
	e = n - 2
	cost = 0
	while e >= 0:
		first = s[e]
		if first == 'A':
			if cost + a <= p:
				cost += a
			else:
				ans = e + 1
				break
		elif cost + b <= p:
			cost += b
		else:
			ans = e + 1
			break
		while e >= 0 and s[e] == first:
			e -= 1
	ans_arr.append(str(ans + 1))
print('\n'.join(ans_arr))


def res(a, b, m, s):
	x = len(s)
	if s[x - 1] != s[x - 2]:
		sum = 0
	elif s[x - 1] == 'A':
		sum = a
	else:
		sum = b
	if sum > m:
		return x
	elif sum == m:
		for v in range(x - 1, 0, -1):
			if s[v] != s[v - 1]:
				return v + 1
		return 1
	for i in range(x - 1, 0, -1):
		g = s[i - 1]
		if s[i] != g:
			if g == 'B':
				sum += b
				if sum > m:
					return i + 1
				elif sum == m:
					for v in range(i - 1, 0, -1):
						if s[v] != s[v - 1]:
							return v + 1
					return 1
			else:
				sum += a
				if sum > m:
					return i + 1
				elif sum == m:
					for v in range(i - 1, 0, -1):
						if s[v] != s[v - 1]:
							return v + 1
					return 1
	return 1
t = int(input())
for i in range(t):
	(a, b, m) = [int(x) for x in input().split()]
	s = input()
	print(res(a, b, m, s))


t = int(input())
for _ in range(t):
	(a, b, p) = map(int, input().split())
	s = input()
	ans = []
	ind = []
	lst = ' '
	for i in range(len(s) - 1):
		if s[i] == lst:
			continue
		lst = s[i]
		if s[i] == 'A':
			cost = a
		else:
			cost = b
		ans.append(cost)
		ind.append(i)
	sum = 0
	res = len(s) - 1
	j = len(ans) - 1
	while j >= 0 and sum + ans[j] <= p:
		sum += ans[j]
		res = ind[j]
		j = j - 1
	print(res + 1)


from collections import defaultdict

def main():
	t = int(input())
	for _ in range(t):
		(a, b, p) = list(map(int, input().split()))
		s = input()
		n = len(s)
		spent = 0
		last = n - 2
		early = n - 1
		while last > -1:
			if last == 0:
				if s[0] == 'A':
					if a > p:
						early += 1
					else:
						early = 1
				elif b > p:
					early += 1
				else:
					early = 1
				break
			elif s[last] != s[last - 1]:
				if s[last] == 'A':
					if a > p:
						early += 1
						break
					else:
						p -= a
						early = last
				elif b > p:
					early += 1
					break
				else:
					p -= b
					early = last
				last -= 1
			else:
				last -= 1
		print(early)
main()


for _ in range(int(input())):
	(a, b, p) = map(int, input().split())
	s = input()
	n = len(s)
	money = [0] * n
	last = 'C'
	for i in range(n - 2, -1, -1):
		if s[i] == last:
			money[i] = money[i + 1]
		elif s[i] == 'A':
			money[i] = money[i + 1] + a
		else:
			money[i] = money[i + 1] + b
		last = s[i]
	for i in range(1, n + 1):
		if money[i - 1] <= p:
			print(i)
			break


N = int(input())
for _ in range(N):
	(a, b, p) = map(int, input().split())
	s = input()
	cost = [0] * len(s)
	if s[0] == 'A':
		cost[0] = a
	else:
		cost[0] = b
	for i in range(1, len(s) - 1):
		if s[i] != s[i - 1]:
			if s[i] == 'A':
				cost[i] = a
			else:
				cost[i] = b
	for i in range(len(s) - 2, -1, -1):
		cost[i] += cost[i + 1]
	for i in range(1, len(s) - 1):
		if cost[i] == cost[i + 1]:
			cost[i] = cost[i - 1]
	(start, end) = (0, len(s))
	min_pos = len(s)
	new_idx = (start + end) // 2
	idx = None
	while idx != new_idx:
		idx = new_idx
		if cost[idx] > p:
			start = idx
		else:
			if idx < min_pos:
				min_pos = idx
			end = idx
		new_idx = (start + end) // 2
	print(min_pos + 1)


for _ in range(int(input())):
	(a, b, p) = map(int, input().split())
	s = input()
	l = len(s)
	d = {'A': a, 'B': b}
	j = l - 2
	count = 0
	last = ''
	while j >= 0:
		if last == s[j]:
			j -= 1
			continue
		last = s[j]
		count += d[s[j]]
		if count > p:
			break
		else:
			j -= 1
	if count > p:
		if j == l - 2:
			print(l)
		else:
			print(j + 2)
	else:
		print(1)


def calcTest():
	(a_cost, b_cost, wallet) = [int(i) for i in input().split(' ')]
	stops = input()
	stop_changes = []
	if stops[0] == 'A':
		stop_changes.append([a_cost, 1])
	else:
		stop_changes.append([b_cost, 1])
	for i in range(len(stops) - 2):
		if stops[i:i + 2] == 'AB':
			stop_changes.append([b_cost, i + 2])
		elif stops[i:i + 2] == 'BA':
			stop_changes.append([a_cost, i + 2])
	running_cost = 0
	last_transport = 1
	if stop_changes[-1][0] > wallet:
		print(len(stops))
		return
	for i in range(len(stop_changes) - 1, -1, -1):
		running_cost += stop_changes[i][0]
		if running_cost > wallet:
			last_transport = stop_changes[i + 1][1]
			break
	print(last_transport)
num_tests = int(input())
for i in range(num_tests):
	calcTest()


t = int(input())
while t:
	(a, b, p) = [int(i) for i in input().split()]
	s = input()
	n = len(s)
	paisa = 0
	i = 1
	while i < n:
		while i < n and s[i] == s[i - 1]:
			i += 1
		if s[i - 1] == 'A':
			paisa += a
		else:
			paisa += b
		i += 1
	i = 1
	while i < n:
		if paisa <= p:
			break
		while i < n and s[i] == s[i - 1]:
			i += 1
		if s[i - 1] == 'A':
			paisa -= a
		else:
			paisa -= b
		i += 1
	print(min(i, n))
	t -= 1


import sys
import math
from collections import defaultdict, deque
input = sys.stdin.readline

def inar():
	return [int(el) for el in input().split()]

def main():
	t = int(input())
	for _ in range(t):
		(a, b, p) = inar()
		st = input().strip()
		n = len(st)
		cost = 0
		if st[n - 2] == 'A':
			cost += a
		else:
			cost += b
		if cost > p:
			print(n)
			continue
		ans = 1
		for i in range(n - 3, -1, -1):
			if st[i] == st[i + 1]:
				continue
			elif st[i] == 'A':
				if cost + a > p:
					ans = i + 2
					break
				else:
					cost += a
			elif cost + b > p:
				ans = i + 2
				break
			else:
				cost += b
		print(ans)
main()


from sys import stdin
input = stdin.readline

def mp():
	return map(int, input().split())

def it():
	return int(input())
for _ in range(it()):
	(a, b, p) = mp()
	s = input()
	s = s[:len(s) - 1]
	if len(s) == 1:
		print(1)
		continue
	m = 0
	ans = len(s)
	for i in range(len(s) - 2, -1, -1):
		if i == 0 or s[i] != s[i - 1]:
			if s[i] == 'A':
				m += a
			else:
				m += b
			if m <= p:
				ans = i + 1
	print(ans)


t = int(input())
for _ in range(t):
	(a, b, p) = map(int, input().split())
	stops = input()
	n = len(stops)
	cur_vihecle = stops[0]
	flag_new_transaport = True
	money_spent_to_get_here = [0 for i in range(n)]
	for i in range(1, n):
		item = stops[i]
		if flag_new_transaport:
			if stops[i - 1] == 'A':
				money_spent_to_get_here[i] = money_spent_to_get_here[i - 1] + a
			else:
				money_spent_to_get_here[i] = money_spent_to_get_here[i - 1] + b
			flag_new_transaport = False
		else:
			money_spent_to_get_here[i] = money_spent_to_get_here[i - 1]
		if item == stops[i - 1]:
			pass
		else:
			pass
			flag_new_transaport = True
	money_spent_to_get_from = [0 for i in range(n)]
	money_spent_to_get_from[0] = money_spent_to_get_here[-1]
	if money_spent_to_get_from[0] <= p:
		ans = 0
	else:
		ans = -1
	for i in range(1, n):
		if ans != -1:
			break
		if stops[i] != stops[i - 1]:
			money_spent_to_get_from[i] = money_spent_to_get_here[-1] - money_spent_to_get_here[i]
			if money_spent_to_get_from[i] <= p:
				ans = i
				break
	if ans == -1:
		print(n)
	else:
		print(ans + 1)


for _ in range(int(input())):
	(a, b, p) = map(int, input().split())
	path = input()
	n = len(path)
	path = path[:n - 1]
	j = n - 2
	curr = 'N'
	while j >= 0 and p >= 0:
		if path[j] != curr:
			curr = path[j]
			if curr == 'A':
				p -= a
			else:
				p -= b
			if p < 0:
				break
		j -= 1
	print(j + 2)


for t in range(int(input())):
	(a, b, p) = map(int, input().split())
	s = list(input())
	n = len(s)
	if p < a and p < b:
		print(n)
		continue
	dp = [0] * n
	st = []
	exc = 0
	loc = []
	for i in range(n):
		if i == 0:
			if s[i] == 'A':
				dp[0] = a
			else:
				dp[0] = b
			st.append(s[i])
		elif st[-1] == s[i]:
			dp[i] = dp[i - 1] + exc
			exc = 0
		else:
			loc.append(i)
			st.pop(0)
			st.append(s[i])
			dp[i] = dp[i - 1] + exc
			if st[0] == 'A':
				exc = a
			else:
				exc = b
	if dp[-1] <= p:
		print(1)
		continue
	for j in loc:
		if dp[-1] - dp[j] <= p:
			print(j + 1)
			break
	else:
		print(n)


from bisect import bisect_left
t = int(input())
for _ in range(t):
	(a, b, p) = map(int, input().split())
	s = input()
	n = len(s)
	if p < min(a, b):
		print(n)
	else:
		cost = [0] * n
		prev = s[-2]
		if s[-2] == 'A':
			cost[-2] = a
		else:
			cost[-2] = b
		for i in range(n - 3, -1, -1):
			curr = s[i]
			cost[i] = cost[i + 1]
			if curr != prev and curr == 'A':
				cost[i] += a
			elif curr != prev and curr == 'B':
				cost[i] += b
			prev = curr
		for i in range(n):
			if cost[i] <= p:
				break
		print(i + 1)


q = int(input())
for u in range(q):
	(a, b, p) = [int(i) for i in input().split()]
	s = input()
	if a > p and b > p:
		print(len(s))
	else:
		s1 = s[::-1]
		i = 1
		summ = 0
		while i < len(s):
			if s1[i] == 'A':
				dob = a
			else:
				dob = b
			if p >= dob + summ:
				summ += dob
				while i + 1 < len(s) and s1[i + 1] == s1[i]:
					i += 1
				i += 1
				ii = i - 1
			else:
				ii = i - 1
				i = len(s)
		print(len(s) - ii)


def homecoming(a, b, p, s):
	n = len(s)
	cost = 0
	dic = {'A': a, 'B': b}
	cost = dic[s[-2]]
	prev = s[-2]
	if cost > p:
		return n
	for i in range(n - 3, -1, -1):
		if prev != s[i]:
			cost += dic[s[i]]
		prev = s[i]
		if cost > p:
			return i + 2
	return 1
for i in range(int(input())):
	[a, b, p] = list(map(int, input().split()))
	s = input()
	print(homecoming(a, b, p, s))


import sys
import string
from collections import Counter, defaultdict
from math import fsum, sqrt, gcd, ceil, factorial
from itertools import combinations, permutations
flush = lambda : sys.stdout.flush
comb = lambda x, y: factorial(x) // factorial(y) // factorial(x - y)
ip = lambda : input()
ii = lambda : int(input())
r = lambda : map(int, input().split())
rr = lambda : list(r())

def solve():
	(a, b, p) = r()
	s = input()
	s = s[:-1]
	s = s[::-1]
	price = {}
	price['A'] = a
	price['B'] = b
	arr = []
	x = 'zzz'
	for (id, i) in enumerate(s):
		if i != x:
			arr.append(x)
			if price[i] > p:
				print(len(s) - id + 1)
				return
			p -= price[i]
			x = i
	print(1)
for _ in range(ii()):
	solve()


for i in range(int(input())):
	params = [int(i) for i in input().split()]
	route = input()
	prev = route[-1]
	c = params[2]
	a = params[0]
	b = params[1]
	p = route[-1]
	cl = [0]
	for i in reversed(route[:-1]):
		if i != p:
			if len(cl) > 1:
				cl.append(cl[len(cl) - 1] + (a if i == 'A' else b))
			else:
				cl.append(a if i == 'A' else b)
		elif len(cl) > 1:
			cl.append(cl[len(cl) - 1])
		else:
			cl.append(a if i == 'A' else b)
		p = i
	stop = 1
	cl = [i for i in reversed(cl)]
	while stop < len(cl) and cl[stop - 1] > c:
		stop += 1
	print(min(stop, len(cl)))


from os import path
import sys
from math import ceil, floor, gcd, log2
from collections import defaultdict, Counter
maxx = float('inf')
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
	I = lambda : int(sys.stdin.buffer.readline())
	tup = lambda : map(int, sys.stdin.buffer.readline().split())
	lint = lambda : [int(x) for x in sys.stdin.buffer.readline().split()]
	S = lambda : sys.stdin.readline().replace('\n', '').strip()
	stpr = lambda x: sys.stdout.write(f'{x}' + '\n')
	star = lambda x: print(' '.join(map(str, x)))
else:
	I = lambda : int(sys.stdin.buffer.readline())
	tup = lambda : map(int, sys.stdin.buffer.readline().split())
	lint = lambda : [int(x) for x in sys.stdin.buffer.readline().split()]
	S = lambda : sys.stdin.readline().replace('\n', '').strip()
	stpr = lambda x: sys.stdout.write(f'{x}' + '\n')
	star = lambda x: print(' '.join(map(str, x)))
input = sys.stdin.readline
for _ in range(int(input())):
	(a, b, p) = map(int, input().split())
	s = list(input().strip())
	(n, t) = (len(s), 0)
	if len(s) > 1:
		if s[-1] != s[-2]:
			t = 1
			s.pop()
			n -= 1
	(st, exp) = ([], 0)
	for i in range(n):
		if not st:
			st.append(s[i])
			if s[i] == 'A':
				exp += a
			else:
				exp += b
		elif s[i] != st[-1]:
			if s[i] == 'A':
				exp += a
			else:
				exp += b
			st.append(s[i])
	if exp <= p:
		print(1)
	else:
		(i, ss, F) = (0, [], True)
		while i < n:
			if len(ss) == 0:
				ss.append(s[i])
				if s[i] == 'A':
					exp -= a
				else:
					exp -= b
				ss.append(s[i])
			elif ss[-1] != s[i]:
				if exp <= p:
					print(i + 1)
					F = False
					break
				if s[i] == 'A':
					exp -= a
				else:
					exp -= b
				ss.append(s[i])
			i += 1
		if F:
			if t:
				print(i + 1)
			else:
				print(i)


from collections import Counter
from collections import defaultdict
import math
t = int(input())
for _ in range(0, t):
	(a, b, c) = list(map(int, input().split()))
	s = input()
	ans = 0
	n = len(s)
	r = c
	for i in range(0, n - 1):
		if s[i] != s[i + 1] or i == n - 2:
			if s[i] == 'A':
				ans = ans + a
			else:
				ans = ans + b
	if ans <= r:
		print(1)
		continue
	flag = False
	for i in range(0, n - 1):
		if s[i] != s[i + 1] or i == n - 2:
			if s[i] == 'A':
				ans = ans - a
			else:
				ans = ans - b
			if ans <= r:
				flag = True
				print(i + 2)
				break


n = int(input())
for i in range(n):
	(a, b, p) = [int(i) for i in input().split()]
	string = input()
	prevDistance = 0
	cost = 0
	stringReverse = string[::-1]
	previousStation = 'C'
	changed = False
	for j in range(1, len(string)):
		if stringReverse[j] != previousStation:
			changed = True
			if stringReverse[j] == 'B':
				cost += b
			else:
				cost += a
			if cost > p:
				print(len(stringReverse) - j + 1)
				break
			prevDistance = j
			previousStation = stringReverse[j]
	if cost <= p:
		print('1')


import sys
input = sys.stdin.readline
from collections import defaultdict as dd
t = int(input())
while t:
	(a, b, p) = map(int, input().split())
	s = input().split()
	s = s[0]
	ss = [s[0]]
	n = len(s)
	ind = [0]
	for i in range(1, n):
		if ss[-1] != s[i]:
			ss.append(s[i])
			ind.append(i)
	if len(ind) > 1:
		if ind[-1] == n - 1:
			ind.pop()
			ss.pop()
	su = 0
	for i in range(len(ss)):
		if ss[i] == 'A':
			su += a
		else:
			su += b
	res = n
	if su <= p:
		res = 1
	i = 0
	while su > p and i < len(ss):
		if ss[i] == 'A':
			su -= a
		else:
			su -= b
		i += 1
	if su <= p and i < len(ind):
		res = ind[i] + 1
	print(res)
	t -= 1


t = int(input())
for i in range(t):
	(a, b, p) = map(int, input().split())
	s = input()
	d = {'B': b, 'A': a}
	dp = [0 for i in range(len(s))]
	dp1 = [0 for i in range(len(s))]
	n = len(s)
	for j in range(1, len(s)):
		if j == 0:
			continue
		if j == len(s) - 1:
			dp[j] = dp[j - 1] + d[s[j - 1]]
		elif s[j] != s[j - 1]:
			dp[j] = dp[j - 1] + d[s[j - 1]]
		elif s[j] == s[j - 1]:
			dp[j] = dp[j - 1]
	for j in range(len(dp)):
		dp1[j] = dp[n - 1] - dp[j]
	for j in range(len(dp1)):
		if dp1[j] <= p:
			print(j + 1)
			break


t = int(input())
for q in range(t):
	(a, b, p) = map(int, input().split())
	s = input()
	arr = [0] * len(s)
	lis = []
	flag = 0
	for i in range(len(s) - 1):
		if s[i] != s[i + 1]:
			if s[i] != s[i + 1]:
				arr[i + 1] = 1
				flag = 1
	if flag == 0:
		if s[0] == 'A' and a <= p or (s[0] == 'B' and b <= p):
			print(1)
			continue
		else:
			print(len(s))
			continue
	for i in range(len(arr)):
		if arr[i] == 1:
			lis.append(i)
	lis.insert(0, 0)
	if lis[len(lis) - 1] != len(s) - 1:
		lis.append(len(s) - 1)
	res = []
	for i in range(len(lis) - 1):
		if s[lis[i]] == 'A':
			res.append(a)
		else:
			res.append(b)
	for i in range(len(res) - 2, -1, -1):
		res[i] += res[i + 1]
	pos = -1
	for i in range(len(res)):
		if res[i] <= p:
			pos = i
			break
	if pos >= 0:
		print(lis[pos] + 1)
	else:
		print(len(s))


for _ in range(int(input())):
	(a, b, p) = map(int, input().split())
	ar = list(input())
	l1 = []
	l2 = []
	ty = ar[0]
	if ar[0] == 'A':
		l1.append(1)
		l2.append(a)
	elif ar[0] == 'B':
		l1.append(1)
		l2.append(b)
	ty = ar[0]
	for i in range(1, len(ar)):
		if ar[i] != ty and i != len(ar) - 1:
			if ar[i] == 'A':
				l1.append(i + 1)
				l2.append(a)
			else:
				l1.append(i + 1)
				l2.append(b)
			ty = ar[i]
	cost = sum(l2)
	flag = True
	for i in range(len(l1)):
		if cost > p:
			cost -= l2[i]
		else:
			flag = False
			break
	if flag:
		print(len(ar))
	else:
		print(l1[i])


for _ in range(int(input())):
	(a, b, p) = map(int, input().split())
	s = input()
	v = [0] * len(s)
	if s[-2] == 'A':
		v[-2] = a
	else:
		v[-2] = b
	for i in range(2, len(s)):
		if s[-1 - i] != s[-i]:
			if s[-i - 1] == 'A':
				v[-1 - i] = v[-i] + a
			else:
				v[-1 - i] = v[-i] + b
		else:
			v[-1 - i] = v[-i]
	for i in range(len(s)):
		if v[i] <= p:
			print(i + 1)
			break


t = int(input())
for T in range(t):
	(a, b, p) = list(map(int, input().split()))
	s = input()
	bus = 0
	tram = 0
	for i in range(len(s) - 1):
		if i > 0:
			if s[i] == 'A' and s[i - 1] != 'A':
				bus += 1
			if s[i] == 'B' and s[i - 1] != 'B':
				tram += 1
		elif s[i] == 'A':
			bus += 1
		elif s[i] == 'B':
			tram += 1
	money_req = bus * a + tram * b
	ans = -1
	if money_req <= p:
		ans = 1
		print(1)
		continue
	else:
		i = 0
		while i < len(s) - 1:
			if i < len(s) - 1 and s[i] == 'A':
				money_req -= a
				while i < len(s) - 1 and s[i] != 'B':
					i += 1
			if money_req <= p:
				ans = i
				break
			if i < len(s) - 1 and s[i] == 'B':
				money_req -= b
			while i < len(s) - 1 and s[i] != 'A':
				i += 1
			if money_req <= p:
				ans = i
				break
	if ans == -1:
		ans = len(s)
	else:
		print(ans + 1)


for _ in range(int(input())):
	(a, b, p) = [int(i) for i in input().strip().split()]
	s = input()
	s = 'X' + s[:-1] + 'X'
	n = len(s)
	cost = [0] * n
	lastchar = 'X'
	for i in range(1, n):
		if s[i] != lastchar:
			if lastchar == 'A':
				cost[i] = a
			elif lastchar == 'B':
				cost[i] = b
			lastchar = s[i]
	exp = 0
	walkto = -1
	for i in range(n - 1, 0, -1):
		if exp + cost[i] > p:
			walkto = i
			break
		exp += cost[i]
	if i == 1:
		walkto = 1
	print(walkto)


for _ in range(int(input())):
	(a, b, p) = map(int, input().split())
	s = input()
	arr = [0 for i in range(len(s))]
	arr[-1] = 0
	if s[-2] == 'B':
		arr[-2] = b
	else:
		arr[-2] = a
	for i in range(len(arr) - 3, -1, -1):
		if s[i + 1] != s[i]:
			if s[i] == 'A':
				arr[i] = arr[i + 1] + a
			else:
				arr[i] = arr[i + 1] + b
		else:
			arr[i] = arr[i + 1]
	for i in range(len(arr)):
		if arr[i] <= p:
			print(i + 1)
			break


t = int(input())
for w in range(t):
	(a, b, n) = map(int, input().split())
	s = input()
	j = len(s) - 1
	if j > 0 and s[j - 1] != s[j]:
		j -= 1
	if s[j] == 'B' and b > n:
		print(len(s))
		continue
	elif s[j] == 'A' and a > n:
		print(len(s))
		continue
	while True:
		if j < 0:
			break
		if s[j] == 'A':
			if n < a:
				break
			n -= a
			while j >= 0 and s[j] == 'A':
				j -= 1
		else:
			if n < b:
				break
			n -= b
			while j >= 0 and s[j] == 'B':
				j -= 1
	print(j + 2)


def solution():
	for _ in range(int(input())):
		(a, b, p) = [int(i) for i in input().split()]
		arr = input()
		current = arr[0]
		from collections import deque
		h = deque()
		h.append((1, a if current == 'A' else b))
		for (i, v) in enumerate(arr[1:-1]):
			if current != v:
				h.append((i + 2, a if v == 'A' else b))
			current = v
		index = 0
		while h:
			(i, t) = h.pop()
			p -= t
			if p < 0:
				break
			else:
				index = i
		if index == 0:
			print(len(arr))
		else:
			print(index)
solution()


import sys
input = lambda : sys.stdin.readline().rstrip()

def main():
	for _ in range(int(input())):
		print(zapr())

def zapr():
	(a, b, p) = map(int, input().split())
	s = input()
	s = s[::-1]
	s = s[1:]
	k = 0
	while k <= len(s) - 1:
		if s[k] == 'A':
			if p >= a:
				p -= a
				while s[k] == 'A':
					k += 1
					if k == len(s):
						break
			else:
				break
		elif s[k] == 'B':
			if p >= b:
				p -= b
				while s[k] == 'B':
					k += 1
					if k == len(s):
						break
			else:
				break
	return len(s) - k + 1
main()


def Homecoming(a, b, p, s):
	n = len(s)
	s = list(s)
	change = []
	for x in range(1, n):
		if x != n - 1 and s[x] != s[x - 1]:
			change.append(x)
		elif x == n - 1:
			change.append(x)
	start = s[0]
	cost = []
	if start == 'A':
		for x in range(len(change)):
			if x % 2 == 0:
				cost.append(a)
			else:
				cost.append(b)
	else:
		for x in range(len(change)):
			if x % 2 == 0:
				cost.append(b)
			else:
				cost.append(a)
	total_cost = sum(cost)
	f = 0
	for x in range(len(cost)):
		if total_cost <= p:
			f = 1
			break
		else:
			total_cost -= cost[x]
	if f == 0:
		x += 1
	if x == 0:
		return 1
	count = 0
	r = x
	for x in range(1, n):
		if x != n - 1 and s[x] != s[x - 1]:
			count += 1
		elif x == n - 1:
			count += 1
		if count == r:
			return x + 1
t = int(input())
for _ in range(t):
	(a, b, p) = map(int, input().split())
	s = input()
	print(Homecoming(a, b, p, s))