I entered in September short can you help me optimize my code for GCD Discount problem

my code is this :

import math
t = int(input())
for _ in range(t):
    n = int(input())
    init = list(map(int, input().split()))
    disc = list(map(int, input().split()))
    checklist = init.copy()
    x = math.gcd(*init)
    for i in range(len(init)):
        checklist[i] = disc[i]
        if x<=math.gcd(*checklist):
            x = math.gcd(*checklist)
        checklist[i] = init[i]

but I get runtime error how can i optimize it?
Problem link: GCD Discount

probably you are getting time limit exceeded and not runtime error. btw your algorithm is not efficient enough. you can precompute a prefix and suffix gcd array. then for every disc[i] the current answer becomes ans=max(gcd(prefix[i-1],disc[i],suffix[i+1]),ans)