#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int main(){
    //freopen("two2.in","r",stdin);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t;cin>>t;
    vector <ll> vv,v;
    while (t--){
        ll n,k,a;
        v.clear();vv.clear();
        cin>>n>>k;
        while (n--){
        	v.push_back(1e18);
        }
        n=v.size();
        for (int i=0;i<k;i++){
        	cin>>a;
        	a--;
        	vv.push_back(a);
        }
        for (int i=0;i<k;i++){
        	cin>>a;
        	v[vv[i]]=a;
        }
        for (int i=1;i<n;i++){
        	v[i]=min(v[i],v[i-1]+1);
        }
        for (int i=n-2;i>=0;i--){
        	v[i]=min(v[i],v[i+1]+1);
        }
        for (int i=0;i<n;i++) cout<<v[i]<<" ";
        cout<<"\n";
    }
    return 0;
}