编程介的小学生 2017-05-05 07:26 采纳率: 20.5%
浏览 793
已采纳

Intricate to death?

Obviously, some of the descriptions are deliberately lengthened, in order to make the whole paragraph more fun. In this problem, your task is similar: given a set of rules, find a description that is at least A characters and at most B characters long. If there are more than one possible description satisfying the condition above, choose the one that comes first lexicographically. Note that shorter answers are NOT always better than longer ones.

BTW: Rules like "Lixiaoyao: Lixiaoyao" looks rather stupid, so don't print things like that, even if no other solutions can be found.

Input

The first line contains a single integer T (T <= 10), the number of test cases. Each case begins with an integer n (1 <= n <= 5), the number of rules, followed by n lines, each describing a rule. Each rule begins with the character's name, then a colon, then a single space, and the description. The description is a list of tokens separated by a single space, with no leading spaces or trailing spaces, followed by a period. Each token is either a word consisting of only lowercase letters, or a character's name, or a character's name, followed by an apostrophe('), then a lowercase letter 's'. A character's name is always an uppercase letter followed by zero or more lowercase letters. No two characters will have the same name, but not all character names appear in the left side of a rule. After the ruleset, you'll be given a single integer q (1 <= q <= 5) on the next line, indicating the number of queries. Each query appears on its own line, containing the name of the character in question, then two integers A and B (1 <= A <= B <= 100), explained above.

Each rule is at least 15 characters, at most 100 characters, containing at least one lowercase token. On the right side of each rule, there will be at most 3 characters involved, all distinct (though one of them may appear on the left side of the rule), and there are no more than 10000 different descriptions for any character in questions, if we only count descriptions only length <= B.

Output

For each test case, print the case number in the first line, then q answers in the following q lines, one for each line. If there is no solution, print 'No solution.' (without quote), otherwise a sentence describing the character. The sentence should be in the same format as a rule in the input. The length of the sentence (including everything: the character's name, the colon, the space, the description, and the final period) should be at least A and at most B.
Sample Input

2
2
Alice: Bob's mother.
Bob: Alice's son.
2
Alice 20 20
Bob 24 25
4
A: B's girlfriend.
B: A's boyfriend.
C: the only person who knows that A and B love each other.
A: D's smallest daughter.
5
A 1 100
C 1 50
C 70 80
C 71 80
C 82 90
Sample Output

Case 1:
Alice: Bob's mother.
Bob: Bob's mother's son.
Case 2:
A: A's boyfriend's girlfriend.
No solution.
C: the only person who knows that A and A's boyfriend love each other.
C: the only person who knows that B's girlfriend and B love each other.
C: the only person who knows that A and B's girlfriend's boyfriend love each other.

  • 写回答

1条回答 默认 最新

报告相同问题?

悬赏问题

  • ¥15 C#调用python代码(python带有库)
  • ¥15 矩阵加法的规则是两个矩阵中对应位置的数的绝对值进行加和
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能
  • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面
  • ¥50 NT4.0系统 STOP:0X0000007B