from sys import stdout
printn = lambda x: stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True  and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

t = inn()
for _ in range(t):
    n,m,a,b = inm()
    a -= 1
    b -= 1
    dst = [ [] for i in range(n) ]
    for i in range(m):
        u,v = inm()
        dst[u-1].append(v-1)
        dst[v-1].append(u-1)

    c = [0]*n
    c[a] = 1
    c[b] = 1
    for x in dst[a]:
        if c[x]==1:
            continue
        q = [x]
        while len(q)>0:
            y = q.pop()
            if c[y]==1:
                continue
            c[y] = 1
            #q.extend(dst[y])
            for z in dst[y]:
                if c[z]==0:
                    q.append(z)
    ddprint(c)
    nb = n-sum(c)

    c = [0]*n
    c[a] = 1
    c[b] = 1
    for x in dst[b]:
        if c[x]==1:
            continue
        q = [x]
        while len(q)>0:
            y = q.pop()
            if c[y]==1:
                continue
            c[y] = 1
            #q.extend(dst[y])
            for z in dst[y]:
                if c[z]==0:
                    q.append(z)
    ddprint(c)
    na = n-sum(c)

    print((na)*(nb))
