8514: link with Level Editor II

内存限制:128 MB 时间限制:8 S
题面:传统 评测方式:文本比较 上传者:
提交:4 通过:1

题目描述

link is playing a game, called Advertising Space for Rent.

In this game, a level consists of several worlds. Each world consists of m nodes and some directed roads. The player starts on node 1 of the first world. In each world, the player can either stay at the current node or go through exactly one road that exists in that world. After that, the player will be teleported to the next world without changing the ID of the node where he stays. If there is no next world, the game ends. The player wins if he ends on node mm.

link is editing a new level, he has already made worlds (numbered from 1 to n) and wants to choose a continuous subsegment of them to form a new level. The only limit is there shouldn't be more than k ways to win. (Two ways are considered different if and only if the operation in some world differs.)

link doesn't want to discard too many worlds. What is the maximum number of worlds link can use in the new level?

输入格式

Each test contains multiple test cases. The first line contains the number of test cases T(1T30). Description of the test cases follows.

The first line contains three integers n,m,k(1n5×103,2m20,1k109).

The following input describes the worlds from 1 to n. For each world:

The first line contains an integer l (0lm×(m1)), which is the number of roads in this world.

The next ll lines, each line contains two integers u,v (1u,vm,u=v), which means there is a road from node u to node v in this world.

For each world, it is guaranteed that there is no duplicate edge.

For each test case, it is guaranteed that the sum of l does not exceed 10^6.

It is guaranteed that the sum of n over all test cases does not exceed 10^5, and the sum of l over all test cases does not exceed 3×106.

输出格式

For each test case, output a single integer, which is the maximum number of worlds link can use in the new level.

输入样例 复制

2
3 3 1
1
2 1
1
2 3
1
1 2
3 3 1
1
1 2
1
1 2
1
2 3

输出样例 复制

3
2