编程介的小学生 2017-04-11 10:59 采纳率: 20.3%
浏览 812
已采纳

Intricate to death?

Task

Have you heard of the game PAL? Many people believe it's the greatest Chinese RPG series so far. There are many characters, including heros and NPCs, summarized in the following paragraph.

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条回答 默认 最新

  • threenewbee 2017-04-29 15:48
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了
  • ¥100 H5网页如何调用微信扫一扫功能?