Given a Complete Binary Tree of ‘n’ depth, you can perform 4 types of mirror operation on the tree:-

Mirror on the right. The tree is mirrored to the right and rightmost node on every level is connected with the mirrored corresponding node.

Mirror on the left. The tree is mirrored to the left and leftmost node on every level is connected with the mirrored corresponding node.

Mirror on the top. The tree is mirrored to the top and topmost nodes are connected with corresponding nodes.

Mirror on the bottom. The tree is mirrored to the bottom and bottom most nodes are connected with the corresponding nodes.

See the image for details.   
Mirror Right:  

Mirror Bottom:   

You are given ‘q’ queries, each performing this type of operation or asking for the no of edges in the produced graph.

Queries are of the form “1 x” or “2” where x is 1 for right, 2 for left, 3 for top or 4 for bottom.

1 x:  Perform x operation on the result graph.

2:     Print the no of edges in the graph. Since it can be very large, print it modulo 1000000007.   

-----Input:-----
- First line will contain $n$, the depth of the initial tree and $q$, the number of queries.    
- Next $q$ lines contain queries of the form "1 $x$" or "2".

-----Output:-----
For each query of type "2", output a single line containing the no of edges in the graph modulo 1000000007.

-----Constraints-----
- $1 \leq n \leq 1000$
- $1 \leq q \leq 10^5$
- $1 \leq x \leq 4$

-----Sample Input:-----
2 3
1 1
1 4
2

-----Sample Output:-----
38

-----EXPLANATION:-----
Initial no of edges = 6

After the operation 1 1, no of edges = 15

After the operation 1 4, no of edges = 38

At operation 2, we print the no of edges that is 38.

```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 = 'def main():\n n,q = list(map(int,input().split()))\n edges = ((pow(2,n,1000000007)-1)*2)%1000000007\n bottom = pow(2,n,1000000007)\n top = 1\n right = n+1\n left = n+1\n\n for i in range(q):\n  query = list(map(int,input().split()))\n  if len(query) == 1:\n   print(edges)\n  else:\n   op = query[1]\n   if op == 1:\n    edges *= 2\n    edges += right\n    edges = edges%1000000007\n    bottom *= 2\n    top *= 2\n   elif op == 2:\n    edges *= 2\n    edges += left\n    edges = edges%1000000007\n    bottom *= 2\n    top *= 2\n   elif op == 3:\n    edges *= 2\n    edges += top\n    edges = edges%1000000007\n    left *= 2\n    right *= 2\n    top = bottom\n   else:\n    edges *= 2\n    edges += bottom\n    edges = edges%1000000007\n    left *= 2\n    right *= 2\n    bottom = top\n\n   left = left%1000000007\n   right = right%1000000007\n   bottom = bottom%1000000007\n   top = top%1000000007\n\nmain()\n'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 13939