#include<bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 2e5 + 5;

int32_t main()
{
    IOS;

    int t;
    cin >> t;

    while (t--)
    {
        int n, k;
        cin >> n >> k;
        vector<int> pos(k + 2), t(n + 2, 2e9);
        for (int i = 1; i <= k; i++) {
            cin >> pos[i];
        }
        for (int i = 1; i <= k; i++) {
            cin >> t[pos[i]];
        }
        vector<int> L(n + 2, 2e9), R(n + 2, 2e9);
        for (int i = 1; i <= n; i++) {
            L[i] = min(L[i - 1] + 1, t[i]);
        }
        for (int i = n; i >= 1; i--) {
            R[i] = min(R[i + 1] + 1, t[i]);
        }
        for (int i = 1; i <= n; i++) {
            cout << min(L[i], R[i]) << ' ';
        }
        cout << endl;
    }

    return 0;
}
