#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

void solve() {
    int n;
    cin >> n;
    
    vector<int> p(n);
    int curr = n - 1;
    
    // Work backwards from the largest index
    while (curr >= 0) {
        // Find the smallest perfect square >= curr
        int root = ceil(sqrt(curr));
        int s = root * root;
        
        // The start of the block that sums to 's'
        int start = s - curr;
        
        // Fill the block in reverse
        for (int i = start; i <= curr; ++i) {
            p[i] = s - i;
        }
        
        // Move to the remaining prefix
        curr = start - 1;
    }
    
    for (int i = 0; i < n; ++i) {
        cout << p[i] << (i == n - 1 ? "" : " ");
    }
    cout << "\n";
}

int main() {
    // Fast I/O
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    
    return 0;
}