Problem hidden
This problem was hidden by Editorial Board member probably because it has incorrect language version or invalid test data, or description of the problem is not clear.

PT07K - Balloons of JiaJia

In WinD's birthday, JiaJia opens a small contest for all guests: just typing all characters from 'a' to 'z', who fastest is the winner. The award is a very big bunch of balloons. Of course, JiaJia hopes his girlfriend - WinD can win, since he only carries two bunches with him and the award for this contest looks prettier. Unfortunately, life is not always as he expected, the winner is Amber. So JiaJia can only give WinD his second bunch of balloons. After the party ended, WinD said "I prefer that bunch of balloons to this one!! If you can't give me something the same as it, I don't want to see you anymore!". Well, JiaJia really has a brainstorm.

If we consider balloons as nodes, the colorful strings connect them as edges, and color of each balloon is label of each node then we have each bunch of balloons is a rooted, labeled, ordered tree.

We call T a labeled tree if each node is assigned a symbol from a fixed finite alphabet. And T is an ordered tree if a left-to-right order among siblings in T is given.

JiaJia can do these 3 operators to change the shape of a bunch of balloons (T):

  • Relabel (recolor a balloon) Change the label of a node v in T.
  • Delete (remove a balloon) Delete a non-root node v in T with parent p, making the children of v become the children of p. The children are inserted in the place of v as a subsequence in the left-to-right order of the children of p.
  • Insert (add a balloon) The complement of Delete. Insert a node v with any label as a child of node p in T, making v be the parent of a consecutive subsequence of the children of p.

Please help the poor guy JiaJia, use as few number of operators to make WinD's bunch of balloons exactly the same as Amber's bunch of balloons. His girlfriend can't wait any longer. Note that, he can only make changes with WinD's bunch.

Input

The input file contains two bunches of balloons (or trees). The first is of WinD, the second is of Amber.

The first line of the input file contains one integer N - number of balloons in the bunch T1 (1 <= N <= 500). Balloons are numbered from 1 to N.

In next N lines, the i-th line contains the ordered children list of the i-th balloon. The first integer l[i] of the i-th line is the color id of the i-th balloon (0 <= l[i] <= 104). The second integer c[i] of the i-th line c[i] is the number of the children of the i-th balloon. Then c[i] integers followed, which means the ordered children list of the i-th balloon.

The remaining part of the input file is the description of the second bunch of balloons T2. The format is the same as T1.

Output

Output minimum number of operators JiaJia needs to do.

Example

Input:
3
1 2 2 3
2 0
1 0
2
1 1 2
3 0

Output:
2

Explanation

We cut the string connected between 1st balloon and 3rd balloons, then change the color of 2nd balloon to 3.

Added by:Thanh-Vy Hua
Date:2007-04-07
Time limit:0.100s-1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:ADA95 ASM32 BASH BF C CSHARP CPP C99 CLPS LISP sbcl LISP clisp D FORTRAN HASK ICON ICK JAVA LUA NEM NICE OCAML PAS-GPC PAS-FPC PERL PHP PIKE PRLG-swi PYTHON RUBY SCM guile SCM qobi ST TEXT WHITESPACE
Resource:Co-author Amber

© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.