#include <bits/stdc++.h>

#define fori(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;

void solve() {

    long long n, k;
    cin >> n >> k;
    std::vector< long long > a(k), t(k);
    fori(i, k) {
        cin >> a[i];
        --a[i];
    }
    fori(i, k) cin >> t[i];

    //std::sort(all(a));

    std::unordered_map< long long, long long> v;
    fori(i, k) {
        v[a[i]] = i;
    }

    std::vector< long long > ans(n, std::numeric_limits<long long>::max() / 2);

    long long min = std::numeric_limits< long long >::max() / 2;
    for(long long i = n - 1; i >= 0; --i, ++min) {
        if(v.find(i) != v.end()) min = std::min(t[v[i]], min);
        ans[i] = std::min(ans[i], min);
    }

    min = std::numeric_limits< long long >::max() / 2;
    for(long long i = 0; i < n; ++i, ++min) {
        if(v.find(i) != v.end()) min = std::min(t[v[i]], min);
        ans[i] = std::min(ans[i], min);
        cout << ans[i] << " ";
    }

    cout << endl;

}

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    long long t;
    cin >> t;

    fori(i, t) {
        solve();
    }

    return 0;
}

