I was practicing the lucky number game problem but whenever I submit my solution it results in Time Limit Exceeded. Please help.

My solution is

```
def main():
T = int(input())
A = []
ans = {}
for j in range(T):
ans.setdefault(j+1,'None')
N = input().split(" ")
a = int(N[1])
b = int(N[2])
N = int(N[0])
A = input().split(" ")
bwins = 0
awins = 0
cmwins = 0
i = len(A)-1
while(i>=0):
if(int(A[i]) % a == 0):
if(int(A[i])%b==0):
cmwins += 1
else:
bwins += 1
A.pop(i)
i = len(A)-1
elif(int(A[i])%b==0):
awins += 1
A.pop(i)
i = len(A)-1
else:
i-=1
if(awins == bwins):
winner = 'BOB'
elif(awins>bwins):
winner = 'ALICE'
else:
winner = 'BOB'
ans[j+1] = winner
for i in range(T):
print(ans[i+1])
if __name__=='__main__':
main()
indent preformatted text by 4 spaces
```