#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define vi vector<int>
#define vii vector<vector<int>>
#define rep(i,a,b) for(int i=a; i<b ; ++i)
#define ff first
#define ss second
#define pb push_back
#define ppb pop_back
ll MOD = 1e9+7;

void solve(){
    int n,k;
    cin >> n >> k;
    ll a[k+1],t[k+1];
    rep(i,1,k+1) cin >> a[i];
    rep(i,1,k+1) cin >> t[i];
    vector<ll> c(n+1,INT_MAX), l(n+1,INT_MAX), r(n+1,INT_MAX);
    rep(i,1,k+1){
        c[a[i]] = t[i];
    }
    rep(i,1,n+1){
        if(i==1) {
            l[i] = c[i];
        }
        else{
            l[i] = min(l[i-1]+1, c[i]);
        }
    }
    for(int i=n;i>0;i--){
        if(i==n) r[i] = c[i];
        else{
            r[i] = min(r[i+1]+1, c[i]);
        }
    }
    for(int i=1;i<=n;i++){
        cout << min(l[i],r[i]) << " ";
    }
    cout << "\n";
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t;
    cin >> t;
    while(t--)
        solve();
    return 0;
}
