Seven Segment Graph

No attempts yetTime limit1sMemory limit128 MB

Problem

A seven segment display shows one digit by turning seven segments on and off. From here on, seven segment display is shortened to SSD.

The seven segments have the names and positions below. The DP segment for the decimal point is not used in this problem.

 AAAA
F    B
F    B
 GGGG
E    C
E    C
 DDDD

The segments meet at six endpoints. Call the top left, top right, middle left, middle right, bottom left and bottom right endpoints LT, RT, LM, RM, LB and RB. Each segment joins the two endpoints below.

SegmentEndpoints
ALT, RT
BRT, RM
CRM, RB
DLB, RB
ELM, LB
FLT, LM
GLM, RM

An SSD lights the following segments to show the digits 00 through 99.

  • 00: A, B, C, D, E, F
  • 11: B, C
  • 22: A, B, G, E, D
  • 33: A, B, C, D, G
  • 44: B, C, F, G
  • 55: A, C, D, F, G
  • 66: A, C, D, E, F, G
  • 77: A, B, C
  • 88: A, B, C, D, E, F, G
  • 99: A, B, C, D, F, G

The display of one digit can be read as a graph. Take the endpoints of the lit segments as nodes and the lit segments themselves as edges, and one graph comes out. Endpoints of segments that stay off are not nodes. The graph obtained this way is called the SSD graph of degree 00.

The SSD graph of degree kk (k>0k > 0) is built by splitting every edge of the degree 00 SSD graph into k+1k+1 edges and inserting kk new nodes in between. In the degree 11 SSD graph, for example, one original edge turns into two edges with one new node between them.

You are given a graph with nn nodes and mm edges. Write a program that finds every SSD graph with the same shape as the given graph, that is, every SSD graph isomorphic to it, and reports its digit and degree.

Input

The first line contains the number of test cases TT (1T201 \le T \le 20). The first line of each test case contains the number of nodes nn (1n5001 \le n \le 500) and the number of edges mm (1m10001 \le m \le 1000). Each of the next mm lines contains the numbers uu and vv of the two nodes an edge joins. Nodes are numbered from 11 to nn. No edge is given twice, and no edge has uu equal to vv.

Output

For each test case, print Case X: Y on the first line, where XX is the test case number and YY is the number of possible (digit, degree) pairs. On each of the next YY lines, print one possible digit and degree separated by a space. Print them in increasing order of digit, and in increasing order of degree when the digit is the same. Print one blank line between test cases.