```
import math
def gcg(a):
gcd = math.gcd(a[0],a[1])
for i in range(2,len(a)):
gcd = math.gcd(gcd,a[i])
return gcd
def optimal(b):
if len(b)==2:
g = sum(b)/math.gcd(*b)
return min(min(b)+1,g)
b.remove(max(b))
gcd = gcg(b)
b.append(gcd)
return sum(b)/gcd
t = int(input())
for _ in range(t):
no_of= int(input())
code = list(map(int,input().split()))
print(int(optimal(code)))
```

I got wrong answer and error but working perfectly fine.