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 mirror_down(e,r,l,u,d):\n edge=(2*e)+d\n right=r*2\n left=l*2\n up=u\n down=u\n #print(edge,right,left,up,down)\n return [edge,right,left,up,down]\ndef mirror_up(e,r,l,u,d):\n edge=(2*e)+u\n right=r*2\n left=l*2\n up=d\n down=d\n #print(edge,right,left,up,down)\n return [edge,right,left,up,down]\ndef mirror_left(e,r,l,u,d):     \n edge=(2*e)+l\n right=r\n left=l\n up=u*2\n down=d*2\n #print(edge,right,left,up,down)\n return [edge,right,left,up,down]\ndef mirror_right(e,r,l,u,d):\n edge=(2*e)+r\n right=r\n left=l\n up=u*2\n down=d*2\n #print(edge,right,left,up,down)\n return [edge,right,left,up,down]\ns=input('').split(' ')\nn,q=(int(s[0]),int(s[1]))\ne=(2**(n+1))-2\nl=n+1\nr=n+1\nu=1\nd=2**n\nwhile(q!=0):\n s=input('').split(' ')\n if(len(s)==2):\n  c=int(s[1])\n  if(c==1):\n   a=mirror_right(e,r,l,u,d)\n   e=a[0]\n   r=a[1]\n   l=a[2]\n   u=a[3]\n   d=a[4]\n  if(c==2):\n   a=mirror_left(e,r,l,u,d)\n   e=a[0]\n   r=a[1]\n   l=a[2]\n   u=a[3]\n   d=a[4]\n  if(c==3):\n   a=mirror_up(e,r,l,u,d)\n   e=a[0]\n   r=a[1]\n   l=a[2]\n   u=a[3]\n   d=a[4]\n  if(c==4):\n   a=mirror_down(e,r,l,u,d)\n   e=a[0]\n   r=a[1]\n   l=a[2]\n   u=a[3]\n   d=a[4]\n  \n else:\n  print(e%1000000007)\n q-=1\n"
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 14235