for _ in range(int(input())): a,b,sx,sy,tx,ty = map(int,input().split()) sx //= a sy //= b tx //= a ty //= b print(abs(sx-tx)+abs(sy-ty))