#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef pair<ll, ll> pii;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    ll q;
    cin >> q;
    for (ll e = 0; e < q; ++e) {
        ll n, k;
        cin >> n >> k;
        vector<pii> a(k);
        for (ll i = 0; i < k; ++i) {
            cin >> a[i].first;
            a[i].first--;
        }
        for (ll i = 0; i < k; ++i) {
            cin >> a[i].second;
        }
        sort(a.begin(), a.end());
        vector<ll> mins(k);
        mins[k - 1] = k - 1;
        for (int i = k - 2; i >= 0; --i) {
            if (a[i].second + a[i].first < a[mins[i + 1]].second + a[mins[i + 1]].first) {
                mins[i] = i;
            } else {
                mins[i] = mins[i + 1];
            }
        }
        ll ind = 0;
        ll x = 0, last = 0;
        for (ll i = 0; i < n; ++i) {
            if (i == ind) {
                ll y = mins[min(x + 1, k - 1)];
                if (a[last].second + abs(i - a[last].first) > a[x].second + abs(i - a[x].first)) {
                     last = x;
                }
                x = y;
                ind = a[y].first;
            }
            cout << min(a[x].second + abs(i - a[x].first), a[last].second + abs(i - a[last].first)) << " ";
        }
        cout << "\n";
    }



    return 0;
}
