#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define ull unsigned long long
#define pb push_back
#define pp pop_back
#define pi pair<ll,ll>
#define pii pair<int,int>
ll mod=1e9+7;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ll n,i,j,k,l,m,b,t,sum,sum1,flag,max1,min1,tmp;
    cin>>t;
    while(t--){
        cin>>n>>m;
        map<ll,ll>mp;
        ll a[m+1],c[m+1];
        multiset<pi>ms;
        for(i=1;i<=m;i++){
            cin>>a[i];
        }
        for(i=1;i<=m;i++){
            cin>>c[i];
            ms.insert({c[i],a[i]});
            mp[a[i]]=c[i];
        }
        ll ans[n+1];min1=1e16;
        for(i=1;i<=n;i++){
            ans[i]=min1;
        }
        sum=1e16;
        //this problem is like AtCoder EDU DP Frog 1 problem
        //Here we first try to reach every position of 1-n from the begining
//        to do that ,we define the min1 as MAXIMUM.Then if we find a position where a air conditioner is placed
//        we then see if we it's less than the minimum values or not
//        if it's less than  (minimum value+1)(this plus 1 is because we have to come 1 step ahead from the previous step),
//        we can use that air conditioned t gain minimum temperature
//        otherwise we have to use the previous Airconditioner to get minimum temperature
//        By this we go from 1 to n and find the minimum values for each index
//Then we go from n to 1 and finding the minimum for every index from last
//if we find any value of ans[] index less than it's already assigned value we update the value


        //Trying from First to last
        for(i=1;i<=n;i++){
            if(mp[i]>0){
                k=mp[i];
                l=min1+1;
                if(k<=l){
                    min1=k;
                }else{
                    min1=l;
                }
                ans[i]=min1;
            }else{
               l=min1+1;
               ans[i]=min(ans[i],l);
               min1++;
            }
        }
        //trying from last to first
        min1=1e16;
        for(i=n;i>=1;i--){
            if(mp[i]>0){
                l=mp[i];
                k=min1+1;
                if(l<=k){
                    min1=l;
                }else{
                    min1=k;
                }
            }else{
                k=min1+1;
                min1++;
            }
            ans[i]=min(min1,ans[i]);
        }

        for(i=1;i<=n;i++){
            cout<<ans[i]<<" ";
        }cout<<endl;

//        for(i=1;i<=n;i++){
//                min1=1e12;
//            for(auto it:ms){
//                k=it.first;
//                l=it.second;
//                j=abs(l-i)+k;
//                if(j<=min1){
//                    min1=j;
//                }else{
//                    if(k>min1){
//                        break;
//                    }
//                }
//            }
//            if(mp[i]>0){
//                min1=min(min1,mp[i]);
//            }
//
//            cout<<min1<<" ";
        }cout<<endl;



}

