------
## 最终结论
```python
def minimal_crossroad_index(test_cases):
    results = []
    for a, b, p, s in test_cases:
        n = len(s)
        min_index = n
        cost = 0
        current_transport = ''
        
        for i in range(n - 1, 0, -1):
            if s[i] != current_transport:
                if s[i] == 'A':
                    cost += a
                else:
                    cost += b
                current_transport = s[i]

            if cost <= p:
                min_index = i
        
        results.append(min_index)
    
    return results

# Read input
t = int(input().strip())
test_cases = [tuple(input().strip().split()[:3]) + (input().strip(),) for _ in range(t)]
test_cases = [(int(a), int(b), int(p), s) for a, b, p, s in test_cases]

# Get results and print them
results = minimal_crossroad_index(test_cases)
for result in results:
    print(result)
```