F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Werewolves

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 183    Accepted Submission(s): 79
Special Judge


Problem Description
There are $n$ players sitting in a row and $m$ kinds of identity cards. The players are numbered from $1\sim n$. The number is public, which means everyone knows the number of each other.

A moderator will give each player an identity card. However, the receiver isn't allowed to view their identity.

Everybody will shut their eyes. Then the moderator will call out each player in turn. All other players' identity cards, disordered, will be shown to that player. The player should guess their identity and shut their eyes afterward. All other players will remain their eyes closed during the procedure.

The players have enough time to discuss before the game starts and want to make sure that at least $\lfloor\frac n m\rfloor$ of the guesses are correct. Please help them make a strategy.
 

Input
The first line contains an integer $T$, denoting the number of testcases.

Each testcase contains two integers $n,m$, separated by a space.

The input guarantees that $2\le m\le n,m^n\le 2.1\times 10^6,\sum m^n\le 1.4\times 10^7$.
 

Output
For each testcase, output $n$ lines, line $p$ denoting the strategy of player $p$.

Denote a sequence $s$ valid if and only if $s$ is a non-descending sequence of length $n-1$ and contains integers in $[1,m]$. Denote the count of valid sequence $c$, then output $c$ integers between $1$ and $m$, the $k$-th integer representing what the player will guess when the multiset of identity cards seen is equal to the multiset of the $k$-th valid sequence sorted in lexicographical order.
 

Sample Input
1 2 2
 

Sample Output
1 2 2 1
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-05-12 04:57:33, Gzip enabled