#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define INF 1000000000
#define pb push_back
#define mp make_pair
#define f first
#define sr second
#define mod 1000000007
int main(){
    int t;
    cin>>t;
    while(t--){
        int n,k; cin>>n>>k;
        int a[k];
        ll ans[n+1];
        for(int i=1;i<=n;i++){
            ans[i]=INT_MAX;
        }
        for(int i=0;i<k;i++){
            cin>>a[i];
        }
        for(int i=0;i<k;i++){
            ll t; cin>>t;
            ans[a[i]]=t;
        }
        ll mn=INT_MAX;
        for(int i=1;i<=n;i++){
            ans[i]=min(ans[i],mn+1);
            mn=ans[i];
        }
        mn=INT_MAX;
        for(int i=n;i>0;i--){
            ans[i]=min(ans[i],mn+1);
            mn=ans[i];
        }
        for(int i=1;i<=n;i++){
            cout<<ans[i]<<" ";
        }
        cout<<endl;
    }
}