Derek loves dominoes. He has his own default domino set which consists of 28 square stones. Every stone is divided in two squares. Each square is marked with zero to six dots.

dominoset
A complete domino set consisting of 28 stones. 

In order to play the game, at least two players are needed. Layla — Derek's sister — refuses to play, because she always loses when she plays against her brother. Out of boredom, Derek thought of two games he can play by himself.

Assignment

Every game starts the same way. Derek randomly chooses a number of domino stones and lays them in a sequence one after another. This sequence doesn't necessarily contain all stones of his domino set. In this assignment, we represent a domino stone as a tuple of two integers, that indicate the number of dots that are on both halves of the stone. A sequence of stones is represented as a list or a tuple of domino stones. In a sequence of domino stones, two stones follow each other if the right side of the left stone is equal to the amount of dots on the left side of the right stone.

The functions above don't depend on each other. It isn't necessary to call on the function beginsequence when implementing the function dominosequence.

Example

>>> sequence = ((3, 0), (0, 1), (1, 2), (0, 2), (0, 0), (3, 3), (1, 1), (2, 3), (3, 1), (2, 2))
>>> beginsequence(reeks)
3
>>> beginsequence (sequence, turn=True)
5

>>> sequence = ((1, 3), (2, 0), (1, 0), (0, 3), (1, 1), (0, 0), (3, 3), (2, 2), (3, 2), (1, 2))
>>> dominosequence(sequence)
[(1, 3), (3, 3), (3, 2), (2, 0), (0, 3)]
>>> dominosequence(sequence, turn=True)
[(1, 3), (3, 0), (0, 2), (2, 2), (2, 3), (3, 3)]