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 = 'MOD=1000000007\nlevels,q=input().split()\nlevels=int(levels)\nq=int(q)\nleft=levels+1\nright=levels+1\ntop=1\nbottom=pow(2,levels)\nedges=0\nf=1\nfor i in range(1,levels+1):\n f=((2%MOD)*(f%MOD))%MOD\n edges+=f\n\nlevels+=1\n\nfor i in range(1,q+1):\n l1=list(map(int,input().split()))\n if(l1[0]==1):\n  y=l1[1]\n  if(y==1):\n   edges=((edges%MOD)*(2%MOD))%MOD\n   edges=((edges%MOD)+(levels%MOD))%MOD\n   top=((top%MOD)*(2%MOD))%MOD\n   bottom=((bottom%MOD)*(2%MOD))%MOD\n  elif(y==2):\n   edges=((edges%MOD)*(2%MOD))%MOD\n   edges=((edges%MOD)+(levels%MOD))%MOD\n   top=((top%MOD)*(2%MOD))%MOD\n   bottom=((bottom%MOD)*(2%MOD))%MOD\n  elif(y==3):\n    edges=((edges%MOD)*(2%MOD))%MOD\n    edges=((edges%MOD)+(top%MOD))%MOD\n    top=bottom;\n    levels=((levels%MOD)*(2%MOD))\n  elif(y==4):\n   edges=((edges%MOD)*(2%MOD))%MOD\n   edges=((edges%MOD)+(bottom%MOD))%MOD\n   bottom=top\n   levels=((levels%MOD)*(2%MOD))\n elif(l1[0]==2):\n  print(edges%MOD)\n'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 13661