def main():
    q = int(input())
    for _ in range(q):
        solve()


def solve():
    k = int(input())
    a1, b1, x1, y1 = map(int, input().split())
    a2, b2, x2, y2 = map(int, input().split())
    if a1*x1+b1*y1 != k or a2*x2+b2*y2 != k:
        print("No")
        return
    if a1*x2+b1*y2 < k and a2*x1+b2*y1 < k:
        print("No")
        return
    print("Yes")


if __name__ == "__main__":
    main()