#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

int main() {
    // Optimize standard I/O operations for speed
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll t;
    cin >> t;
    while (t--) {
        ll m, n;
        cin >> m >> n;
        
        vector<int> b(n + 1);
        ll total_1 = 0, total_2 = 0;
        ll r1 = 0, r5 = 0;
        
        // Pass 1: Read array and calculate initial sums for index 1
        for (ll i = 1; i <= n; i++) {
            cin >> b[i];
            if (b[i] == 1 || b[i] == 3) {
                total_1++;
                r1 += (i - 1); // Distance from index 1
            }
            if (b[i] == 2 || b[i] == 3) {
                total_2++;
                r5 += (i - 1); // Distance from index 1
            }
        }
        
        ll left_1 = 0, left_2 = 0;
        
        // Pass 2: Calculate for each index i by shifting the reference point
        for (ll i = 1; i <= n; i++) {
            cout << abs(r1 - r5) << " ";
            
            // Update the count of elements seen so far (<= i)
            if (b[i] == 1 || b[i] == 3) left_1++;
            if (b[i] == 2 || b[i] == 3) left_2++;
            
            // Shifting index from i to i+1:
            // Elements on the left increase distance by 1, elements on the right decrease by 1
            r1 += 2 * left_1 - total_1; 
            r5 += 2 * left_2 - total_2;
        }
        cout << "\n";
    }

    return 0;
}