{"trustable":false,"sections":[{"title":"","value":{"format":"HTML","content":"\n \u003cdiv class\u003d\"ptx\" lang\u003d\"en-US\"\u003e\n 人们是不同的。一些人偷偷地阅读满是有趣的女孩照片的杂志,有些人在地窖里制造了一个原子弹,其他人则喜欢使用窗户,有些则像很难的数学游戏。最新的市场调查表明,这一细分市场迄今被低估,而且缺乏此类游戏。因此,这种游戏被纳入了KOKOD AKH。规则如下: \u003cbr\u003e \n \u003cbr\u003e每个玩家选择两个数字AI和毕,并把它们写在一张纸条上。其他人看不到数字。在一个给定的时刻,所有的玩家都向其他人展示他们的数字。目标是从所有玩家中确定包括Ai Bi在内的所有表达式的总和,并用给定的m来确定除法后的其余部分。获胜者是首先确定正确结果的人。根据玩家的经验,可以通过选择更高的数字来增加难度。 \n \u003cbr\u003e \n \u003cbr\u003eYou should write a program that calculates the result and is able to find out who won the game. \n \u003cbr\u003e 你应该写一个程序来计算结果,并找出谁赢得了比赛。 \n \u003cbr\u003e\n \u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\n \u003cdiv class\u003d\"ptx\" lang\u003d\"en-US\"\u003e\n The input consists of Z assignments. The number of them is given by the single positive integer Z appearing on the first line of input. Then the assignements follow. Each assignement begins with line containing an integer M (1 \u0026lt;\u003d M \u0026lt;\u003d 45000). The sum will be divided by this number. Next line contains number of players H (1 \u0026lt;\u003d H \u0026lt;\u003d 45000). Next exactly H lines follow. On each line, there are exactly two numbers Ai and Bi separated by space. Both numbers cannot be equal zero at the same time. \n \u003c/div\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\n \u003cdiv class\u003d\"ptx\" lang\u003d\"en-US\"\u003e\n For each assingnement there is the only one line of output. On this line, there is a number, the result of expression \n \u003cbr\u003e\n \u003cp align\u003d\"CENTER\"\u003e\u003cvar\u003e(A\u003csub\u003e1\u003csup\u003eB\u003csub\u003e1+A\u003csub\u003e2\u003csup\u003eB\u003csub\u003e2+ ... +A\u003csub\u003eH\u003csup\u003eB\u003csub\u003eH)mod M.\u003c/sub\u003e\u003c/sup\u003e\u003c/sub\u003e\u003c/sub\u003e\u003c/sup\u003e\u003c/sub\u003e\u003c/sub\u003e\u003c/sup\u003e\u003c/sub\u003e\u003c/var\u003e\u003c/p\u003e\n \u003c/div\u003e"}},{"title":"Sample Input","value":{"format":"HTML","content":"\u003cpre class\u003d\"sio\"\u003e3\n16\n4\n2 3\n3 4\n4 5\n5 6\n36123\n1\n2374859 3029382\n17\n1\n3 18132\n\u003c/pre\u003e"}},{"title":"Sample Output","value":{"format":"HTML","content":"\u003cpre class\u003d\"sio\"\u003e2\n13195\n13\n\u003c/pre\u003e"}}]}