Journey

Time limit1sMemory limit128 MB

Problem

A robot lives on the Cartesian plane and loves walking around it. One day it planned an elaborate journey and wrote a program to follow. The program consists of $n$ functions $f_1, f_2, \dots, f_n$. The $i$-th function $f_i$ is a sequence of $c_i$ commands, where each command is one of the following:

  • GO — move forward one meter.
  • LEFT — turn 90 degrees counterclockwise (to the left).
  • RIGHT — turn 90 degrees clockwise (to the right).
  • F$k$ — execute every command of function $f_k$, then continue with the current function.

The robot starts at home, the point $(0, 0)$, initially facing the positive direction of the $x$-axis, and begins by executing function $f_1$.

For example, consider the functions

  • $f_1$: GO F2 GO F2 GO F2
  • $f_2$: F3 F3 F3 F3
  • $f_3$: GO LEFT

For these functions the robot traces a particular path across the plane.

A journey may never finish. For instance, a program with the single function $f_1$ equal to GO F1 makes the robot keep moving forward forever.

The robot wonders how far from home it gets. Consider the set of all points the robot visits during its journey and find the maximum value of $|x| + |y|$ over those points. If the robot visits points with arbitrarily large $|x| + |y|$, the answer is Infinity.

Input

The first line contains an integer $n$ ($1 \le n \le 100$).

Each of the next $n$ lines describes one function. The $i$-th of these lines starts with an integer $c_i$ ($1 \le c_i \le 100$), the number of commands in $f_i$, followed by the $c_i$ commands themselves. Every command is one of GO, LEFT, RIGHT, or F$k$ (with $1 \le k \le n$), and consecutive tokens are separated by single spaces.

Output

Print a single line with the maximum value of $|x| + |y|$ over all points the robot visits during its journey. If the robot reaches points with arbitrarily large $|x| + |y|$, print Infinity instead.