There are 2N balls in the xy-plane. The coordinates of the i-th of them is (x_i, y_i).
Here, x_i and y_i are integers between 1 and N (inclusive) for all i, and no two balls occupy the same coordinates.
In order to collect these balls, Snuke prepared 2N robots, N of type A and N of type B.
Then, he placed the type-A robots at coordinates (1, 0), (2, 0), ..., (N, 0), and the type-B robots at coordinates (0, 1), (0, 2), ..., (0, N), one at each position.
When activated, each type of robot will operate as follows.
 - When a type-A robot is activated at coordinates (a, 0), it will move to the position of the ball with the lowest y-coordinate among the balls on the line x = a, collect the ball and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything.
 - When a type-B robot is activated at coordinates (0, b), it will move to the position of the ball with the lowest x-coordinate among the balls on the line y = b, collect the ball and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything.
Once deactivated, a robot cannot be activated again. Also, while a robot is operating, no new robot can be activated until the operating robot is deactivated.
When Snuke was about to activate a robot, he noticed that he may fail to collect all the balls, depending on the order of activating the robots.
Among the (2N)! possible orders of activating the robots, find the number of the ones such that all the balls can be collected, modulo 1 000 000 007.

-----Constraints-----
 - 2 \leq N \leq 10^5
 - 1 \leq x_i \leq N
 - 1 \leq y_i \leq N
 - If i ≠ j, either x_i ≠ x_j or y_i ≠ y_j.

-----Inputs-----
Input is given from Standard Input in the following format:
N
x_1 y_1
...
x_{2N} y_{2N}

-----Outputs-----
Print the number of the orders of activating the robots such that all the balls can be collected, modulo 1 000 000 007.

-----Sample Input-----
2
1 1
1 2
2 1
2 2

-----Sample Output-----
8

We will refer to the robots placed at (1, 0) and (2, 0) as A1 and A2, respectively, and the robots placed at (0, 1) and (0, 2) as B1 and B2, respectively.
There are eight orders of activation that satisfy the condition, as follows:
 - A1, B1, A2, B2
 - A1, B1, B2, A2
 - A1, B2, B1, A2
 - A2, B1, A1, B2
 - B1, A1, B2, A2
 - B1, A1, A2, B2
 - B1, A2, A1, B2
 - B2, A1, B1, A2
Thus, the output should be 8.

```python

USER_FILENAME = "<user_code>"
import sys, json, builtins
import math, heapq, bisect, itertools, functools, collections, statistics, fractions, decimal, operator, array, random, re, string, os, pathlib
try:
    import resource as _res
except Exception:
    _res = None
from collections import Counter, defaultdict, deque, OrderedDict
from functools import lru_cache, reduce
from itertools import accumulate, permutations, combinations, product
from math import gcd, ceil, floor, sqrt
from decimal import Decimal
try:
    from typing import *
except Exception:
    pass
try:
    sys.setrecursionlimit(1_000_000)
except Exception:
    pass
try:
    import site as _site
    try:
        _sys_sites = _site.getsitepackages() if hasattr(_site, "getsitepackages") else []
        for _p in _sys_sites:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
    try:
        _usp = _site.getusersitepackages()
        if isinstance(_usp, str):
            _usp = [_usp]
        for _p in _usp:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
except Exception:
    pass

ns = {"__name__": "__main__"}
for _k, _v in list(globals().items()):
    if not _k.startswith("_"):
        ns[_k] = _v
_CODE = 'import sys\ninput = sys.stdin.readline\n\nMOD = 10**9 + 7\n\nN = int(input())\nball = (tuple(int(x) for x in row.split()) for row in sys.stdin.readlines())\n\n# x座標を1,2,...,N\n# y座標をN+1,N+2,...,N+N\n\ngraph = [set() for _ in range(N+N+1)]\nfor x,y in ball:\n    graph[x].add(y+N)\n    graph[y+N].add(x)\n\nvisited = [False] * (N+N+1)\ncomponents = []\nfor x in range(1,N+N+1):\n    if visited[x]:\n        continue\n    V = set([x])\n    E = []\n    q = [x]\n    visited[x] = True\n    while q:\n        y = q.pop()\n        for z in graph[y]:\n            if y < z:\n                E.append((y,z))\n            if visited[z]:\n                continue\n            V.add(z)\n            visited[z] = True\n            q.append(z)\n    components.append((V,E))\n\ndef make_get_pattern(V):\n    deg1 = [x for x in V if len(graph[x]) == 1]\n    get = {}\n    while deg1:\n        x = deg1.pop()\n        if not graph[x]:\n            continue\n        y = graph[x].pop()\n        se = graph[y]; se.remove(x)\n        if len(se) == 1: deg1.append(y)\n        if x < y:\n            get[(x,y)] = 0\n        else:\n            get[(y,x)] = 1\n    for x in V:\n        if graph[x]:\n            y = graph[x].pop()\n            break\n    # 残りはサイクル\n    graph[y].remove(x)\n    if x > y: x,y = y,x\n    get[(x,y)] = 2\n    while graph[x]:\n        y = graph[x].pop()\n        graph[y].remove(x)\n        if x < y:\n            get[(x,y)] = 3\n        else:\n            get[(y,x)] = 2\n        x = y\n    return get\n\ndef F(V,E):\n    # V is connected\n    if len(E) != len(V):\n        return 0\n    ret = 0\n    E.sort()\n    get = make_get_pattern(V)\n    den1,den2 = 1,1\n    dp1 = {x:0 for x in V}\n    dp2 = {x:0 for x in V}\n    for x,y in E:\n        if get[(x,y)] == 0:\n            k1 = dp1[x] + 1; k2 = dp2[x] + 1\n        elif get[(x,y)] == 1:\n            k1 = dp1[y] + 1; k2 = dp2[y] + 1\n        elif get[(x,y)] == 2:\n            k1 = dp1[x] + 1; k2 = dp2[y] + 1\n        else:\n            k1 = dp1[y] + 1; k2 = dp2[x] + 1\n        dp1[x] += k1; dp1[y] += k1\n        dp2[x] += k2; dp2[y] += k2\n        den1 *= k1; den2 *= k2\n        den1 %= MOD; den2 %= MOD\n    return sum(pow(x,MOD-2,MOD) for x in (den1,den2))\n\nprob = 1\nfor c in components:\n    prob *= F(*c)\n    prob %= MOD\n\nanswer = prob\nfor n in range(1,N+N+1):\n    answer *= n\n    answer %= MOD\nprint(answer)'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 14361