#include <bits/stdc++.h>
using namespace std;
#define ll long long int

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    cin>>t;
    while(t--){
        ll n,k,temp;
        cin>>n>>k;
        vector<pair<ll,ll> > v;
        for(int i=0;i<k;i++){
            cin>>temp;
            v.push_back(make_pair(temp,0));
        }
        for(int i=0;i<k;i++){
            cin>>temp;
            v[i].second=temp;
        }
        sort(v.begin(),v.end());
        ll cur=-1;
        vector<ll> ans;
        vector<ll> pre,sur(k);
        for(int i=0;i<k;i++){
            if(i==0){
                pre.push_back(v[i].second-v[i].first);
            }
            else{
                pre.push_back(min(v[i].second-v[i].first,pre[i-1]));
            }
        }
        for(int i=k-1;i>=0;i--){
            if(i==k-1){
                sur[i]=(v[i].second+v[i].first);
            }
            else{
                sur[i]=(min(v[i].second+v[i].first,sur[i+1]));
            }
        }
        for(int i=0;i<n;i++){
            while(cur+1<k && v[cur+1].first<=i){
                cur++;
            }
            ll mn=LONG_MAX;
            if(cur>=0){
                mn=min(mn,pre[cur]+i+1);
            }
            if(cur+1<k){
                mn=min(mn,sur[cur+1]-i-1);
            }
            ans.push_back(mn);
        }
        for(int i=0;i<ans.size();i++){
            cout<<ans[i]<<" ";
        }
        cout<<"\n";
    }
}