B. Roof Construction

time limit per test

1 second

memory limit per test

256 megabytes

It has finally been decided to build a roof over the football field in School 179. Its construction will require placing n consecutive vertical pillars. Furthermore, the headmaster wants the heights of all the pillars to form a permutation p of integers from 0 to n−1, where pi is the height of the i-th pillar from the left (1≤i≤n).

As the chief, you know that the cost of construction of consecutive pillars is equal to the maximum value of the bitwise XOR of heights of all pairs of adjacent pillars. In other words, the cost of construction is equal to max1≤i≤n−1pi⊕pi+1, where ⊕ denotes the bitwise XOR operation.

Find any sequence of pillar heights p of length n with the smallest construction cost.

In this problem, a permutation is an array consisting of n distinct integers from 0 to n−1 in arbitrary order. For example, 2,3,1,0,4 is a permutation, but 1,0,1 is not a permutation (1 appears twice in the array) and 1,0,3 is also not a permutation (n=3, but 3 is in the array).

Input

Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104). Description of the test cases follows.

The only line for each test case contains a single integer n (2≤n≤2⋅105) --- the number of pillars for the construction of the roof.

It is guaranteed that the sum of n over all test cases does not exceed 2⋅105.

Output

For each test case print n integers p1, p2, ..., pn --- the sequence of pillar heights with the smallest construction cost.

If there are multiple answers, print any of them.

Example

Input

Copy

复制代码

4

2

3

5

10

Output

Copy

复制代码
0 1
2 0 1
3 2 1 0 4
4 6 3 2 0 8 9 1 7 5

Note

For n=2 there are 2 sequences of pillar heights:

  • 0,1 --- cost of construction is 0⊕1=1.
  • 1,0 --- cost of construction is 1⊕0=1.

For n=3 there are 6 sequences of pillar heights:

  • 0,1,2 --- cost of construction is max(0⊕1,1⊕2)=max(1,3)=3.
  • 0,2,1 --- cost of construction is max(0⊕2,2⊕1)=max(2,3)=3.
  • 1,0,2 --- cost of construction is max(1⊕0,0⊕2)=max(1,2)=2.
  • 1,2,0 --- cost of construction is max(1⊕2,2⊕0)=max(3,2)=3.
  • 2,0,1 --- cost of construction is max(2⊕0,0⊕1)=max(2,1)=2.
  • 2,1,0 --- cost of construction is max(2⊕1,1⊕0)=max(3,1)=3.

解题说明:此题是一道数学题,为了保证值最小,找规律能发现要让相邻两个数的高位尽量相等。

cpp 复制代码
#include <stdio.h>

int main() 
{
    int tt;
    scanf("%d", &tt);
    while (tt--) 
    {
        int n;
        scanf("%d", &n);
        int k = 1;
        while (k < n) 
        {
            k *= 2;
        }
        k /= 2;
        for (int i = 1; i < n; i++) 
        {
            if (i == k) 
            {
                printf("0 %d ", k);
            }
            else
            {
                printf("%d ", i);
            }
        }
        printf("\n");
    }
    return 0;
}
相关推荐
是隼人7 小时前
buuctf-pwn xdctf2015_pwn200题解(学习过程持续更新)
c语言·学习·安全·pwn入门·ctf入门
布莱克60510 小时前
数组详解:定义、作用、应用场景及与链表的区别(C/C++ 代码讲解)
c语言·开发语言·c++·数组
hongmai66688810 小时前
MP2348GTL-Z:这颗24V/4A同步降压芯片,把性能和体积平衡得恰到好处
c语言·开发语言·arm开发·单片机·5g
多弗朗皮卡丘10 小时前
C语言梦开始的地方19:文件操作
c语言·开发语言
万法若空11 小时前
C/C++ 类型别名定义方式对比
java·c语言·c++
一直C14 小时前
Linux系统编程|进程间通信IPC全套详解(1)(管道、信号)
linux·c语言·开发语言·网络·青少年编程·visual studio code
春风解人意14 小时前
从零开始学习嵌入式P28----线程
c语言·学习·算法
luj_176814 小时前
合法避税与投资评估实战指南
c语言·开发语言·网络·经验分享·算法
一直C15 小时前
Linux系统编程|信号进阶 + SystemV IPC(消息队列、共享内存)
linux·c语言·开发语言·算法·青少年编程·vim
新时代牛马16 小时前
SPL-TPL 链式启动:spl.c 与CONFIG_TPL 三阶段加载
c语言·开发语言