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.
# cook your dish here
n,q=map(int,input().split())
edges=2*(2**n-1)
side_nodes=n+1
top_nodes=1
bottom_nodes=2**n
for i in range(q):
 query=list(map(int,input().split()))
 if query[0]==1:
  if query[1]==1 or query[1]==2:
   edges=edges*2+side_nodes
   top_nodes*=2
   bottom_nodes*=2
  elif query[1]==3:
   edges=edges*2+top_nodes
   top_nodes=bottom_nodes
   side_nodes*=2
  else:
   edges=edges*2+bottom_nodes
   bottom_nodes=top_nodes
   side_nodes*=2
 else:
  print(edges%1000000007)
# cook your dish here
n,q=map(int,input().split())
edges=2*(2**n-1)
side_nodes=n+1
top_nodes=1
bottom_nodes=2**n
for i in range(q):
 query=list(map(int,input().split()))
 if query[0]==1:
  if query[1]==1 or query[1]==2:
   edges=edges*2+side_nodes
   top_nodes*=2
   bottom_nodes*=2
  elif query[1]==3:
   edges=edges*2+top_nodes
   top_nodes=bottom_nodes
   side_nodes*=2
  else:
   edges=edges*2+bottom_nodes
   bottom_nodes=top_nodes
   side_nodes*=2
 else:
  print(edges%1000000007)