Who Wants to Live Forever?

Time limit1sMemory limit128 MB

Summary
Decide whether a bit string evolving under the Rule 90 XOR-neighbor cellular automaton eventually becomes all zeros or oscillates forever.
Level

Hard8 of 10

Topics
Bit manipulation, Math, Simulation, Number theory
Solved
No attempts yet

Problem

Digital physics is a collection of ideas and hypotheses built around the notion of a computable universe. Perhaps our universe is just a large program running on a Turing machine? Is the state of the universe finite? Will the universe eventually end? For now we can only theorize.

To push the frontier of digital physics a little further, consider a specific toy model of the universe — we will call it Bitverse — and decide whether its life comes to an end or it keeps evolving forever.

Bitverse is a single row of nn bits, each either 00 or 11. The universe comes into being as one particular row of bits — an event we call the Bit Bang — and from then on it evolves in discrete steps.

The rule is simple. To compute the next value of the ii-th bit, look at the current values of its neighbours at positions i−1i-1 and i+1i+1 (a neighbour that falls outside the row is treated as 00). If exactly one of the two neighbours is 11, the next value of the ii-th bit is 11; otherwise it is 00. Every bit is updated simultaneously, so the next state depends only on the previous state.

The universe is dead once it consists solely of zeros.

Given the state of Bitverse at the Bit Bang, answer the fundamental question: will Bitverse live forever, or will it eventually die?

Input

The first line contains the number of test cases TT.

Each of the following TT lines contains one test case: a string of between 11 and 200 000200\,000 characters, each either 0 or 1, describing the initial state of a Bitverse.

Output

For each test case print a single line: LIVES if that universe evolves forever, or DIES if it eventually becomes all zeros. Print the answers in the same order as the input.

Hint

The first sample universe never becomes all zeros; it keeps oscillating: 01 → 10 → 01 → … . The second one dies after a few steps: 0010100 → 0100010 → 1010101 → 0000000. The third one is a fixed point and never changes.

Examples3

  1. Example 1

    Input
    3
    01
    0010100
    11011
    
    Expected output
    LIVES
    DIES
    LIVES
    
  2. Example 2

    Input
    2
    1
    0
    
    Expected output
    DIES
    DIES
    
  3. Example 3

    Input
    4
    00
    01
    10
    11
    
    Expected output
    DIES
    LIVES
    LIVES
    LIVES