This code works correctly on ideone but on submission on spoj it says wrong answer , please tell where i am getting wrong.
def gcd(a,b):
if(a==0):
return b
else:
return gcd(b%a,a)
t=int(input())
for i in range(0,t):
n,a,b=input().split()
a=int(a)
b=int(b)
n=int(n)
h=gcd(a,b)
if(h==1): #if the HCF of numbers is 1
for j in range(a,n):
if(j%a==0):
print(j,end=" ")
else:
for j in range(a,n):
if(j%a==0):
if(j%b!=0):
print(j,end=" ")
print()