#include <iostream>
#include <queue>
using namespace std;
int n, k;
bool check(int x)
{
if (x % k == 0 || (x % 10) == k) return true;
return false;
}
int main()
{
cin >> n >> k;
queue<int> q;
for (int i = 1; i <= n; i ++ ) q.push(i);
int j = 1; // 从1开始报数
while (q.size() > 1)
{
int t = q.front();
q.pop();
if (!check(j)) q.push(t); // 如果这个数不用出局,那就再加到队尾
j ++ ;
}
cout << q.front() << endl;
return 0;
}
#include <iostream>
using namespace std;
const int N = 55;
int n;
int ne[N];
int main()
{
int T;
cin >> T;
while (T -- )
{
cin >> n;
for (int i = 1; i < n; i ++ ) ne[i] = i + 1;
ne[n] = 1;
int p = n;
for (int i = 0; i < n; i ++ )
{
p = ne[ne[p]]; // 走两步
cout << ne[p] << ' ';
ne[p] = ne[ne[p]]; // 删掉一个节点
}
cout << endl;
}
return 0;
}