my both code giving run time erroe(NZEC)
from fractions import gcd
t=int(input())
for i in range(t):
a,b=map(int,raw_input().split())
x=gcd(a,b)
print (x)
and another one
def gcd(n1,n2):
if(n2==0):
return n1
elif(n1==0 and n2==0):
return 0
else:
return gcd(n2,n1%n2)
t=int(input())
for i in range(t):
n1,n2=map(int,raw_input().split())
x=gcd(n1,n2)
print (x)
how to fix this error??