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

Starter code:

Solutions:
t=int(input())

for tt in range(t):
    a,b,p=map(int,input().split())
    s=input()
    n=len(s)
    cost = [0]*n
    cost[-1] = 0
    typ = ''
    i=n-2
    while i>=0:
        if s[i]==typ:
            cost[i] = cost[i+1]
        else:
            typ = s[i]
            cost[i] = cost[i+1] + (a if typ=='A' else b)
        i-=1
    i=0
    while cost[i] > p:
        i+=1
    print(i+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)


# from collections import defaultdict

for _ in range(int(input())):
	# n = 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

from math import *
from collections import *
t = int(input())
for y in range(t):
	a,b,p = map(int,input().split())
	s = input()
	n = len(s)
	i = n-2
	ans = n
	ct = 0
	while(i >= 0):
		st = s[i]
		while(i >= 0 and s[i] == st):
			i -= 1
		if(st == 'A'):
			ct += a
		else:
			ct += b
		if(ct <= p):
			ans = i+2
	print(ans)

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
    else:
        if 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 i in range(t):
    a, b, p = list(map(int, input().split()))
    s = input()
    n = len(s)
    ind = n
    sum = 0
    while sum <= p and ind > 0:
        ind -= 1
        if ind == n - 1 or s[ind - 1] != s[ind]:
            if s[ind - 1] == "A":
                sum += a
            else:
                sum += b
    print(ind + 1)


t = int(input())
for tt 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:
		# print(tt, i)
		c += cs[s[i-1]]
		i -= 1
		while i > 0 and s[i-1] == s[i]:
			i -= 1
	print(i+1)



"""
NTC here
""" 
import sys
inp= sys.stdin.readline
input = lambda : inp().strip()
# flush= sys.stdout.flush
# import threading
# sys.setrecursionlimit(10**6)
# threading.stack_size(2**26)

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)
        #print(ans)


main()

#threading.Thread(target=main).start()



for _ in range(int(input())):
    a, b, p = list(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)


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 _ 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)

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)

# from collections import deque
import sys
input = lambda: sys.stdin.readline().strip()
def d(x):
    if x=='A':
        return a
    return b
def f(j):
    su = d(s[j])
    for i in range(j+1, len(s) - 1):
        if s[i]!=s[i-1]:
            su+=d(s[i])
    return su
for i in range(int(input())):
    a,b,p = map(int,input().split())
    s = list(input())
    l = -1
    r = len(s)-1
    while r - l > 1:
        m = (r + l) // 2
        if f(m) > p:
            l = m
        else:
            r = m
    print(r+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]
        else:
            if s[i] == 'A':
                dp[i] = dp[i + 1] + a
            else:
                dp[i] = dp[i + 1] + b
    #print(dp)
    for i in range(l):
        if p >= dp[i]:
            print(i + 1)
            break


# import sys
# input = sys.stdin.readline

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)

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
    # print(cost)
    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)

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(1e9 + 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 = []
    # print(stack)

    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

for _ in range(int(input())):
    a, b, p = map(int, input().split())
    s = input()
    
    d = {'A': a, 'B': b}

    c = '0'
    inv = []
    start = 0
    for i in range(1, len(s)):
        if s[i] != s[i-1]:
            inv.append((start, i, s[i-1]))
            start = i
        elif i == len(s) - 1:
            inv.append((start, i, s[i]))

    ans, cost = len(s) - 1, 0
    for q in inv[::-1]:
        cost += d[q[2]]
        if cost > p:
            break
        else:
            ans = q[0]

    print(ans + 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
            else:
                if 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)

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 = list(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
        #print(ub, 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)))
    


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)