#include<bits/stdc++.h>
#include <cmath>
#include <complex>
using namespace std;
#define ll long long
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define dcm(a) setprecision(a)<<fixed
#define MOD 1000000007
#define clr(memo, a) memset(memo,a,sizeof(memo))
#define PI acos(-1)
typedef complex<double> point;
double  EPS=1e-8;
int dcmp(double x, double y) {	return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1;	}
#define X real()
#define Y imag()
#define angle(a)                (atan2((a).imag(), (a).real()))
#define vec(a,b)                ((b)-(a))
#define same(p1,p2)             (dp(vec(p1,p2),vec(p1,p2)) < EPS)
#define dp(a,b)                 ( (conj(a)*(b)).real() )	// a*b cos(T), if zero -> prep
#define cp(a,b)                 ( (conj(a)*(b)).imag() )	// a*b sin(T), if zero -> parllel
#define length(a)               (hypot((a).imag(), (a).real()))
#define normalize(a)            (a)/length(a)
#define rotateO(p,ang)          ((p)*exp(point(0,ang)))
#define rotateA(p,ang,about)  (rotateO(vec(about,p),ang)+about)
#define reflectO(v,m)  (conj((v)/(m))*(m))
int const N=3e5+5;
ll a[N];
ll t[N];
ll ans[N];
void solve()
{
    priority_queue<pair<ll,int> ,vector<pair<ll,int> >,greater<pair<ll,int> > > pq;
    int n,m;
    cin>>n>>m;
    for(int i=0;i<n;i++)
        ans[i]=0;
    for(int i=0;i<m;i++)
        cin>>a[i];
    for(int i=0;i<m;i++)
        cin>>t[i];
    for(int i=0;i<m;i++){
        pq.push({t[i]+a[i]-1,a[i]-1});
    }
    for(int i=0;i<n;i++){
        if(pq.empty())
        break;
        auto x=pq.top();
        if(x.second<i){
            pq.pop();
            i--;
            continue;
        }
        ans[i]=x.first-i;
    }
    while(!pq.empty())
        pq.pop();
      for(int i=0;i<m;i++){
        pq.push({t[i]+(n-a[i]),a[i]-1});
    }
      for(int i=n-1;i>=0;i--){
        if(pq.empty())
        break;
        auto x=pq.top();
        if(x.second>i){
            pq.pop();
            i++;
            continue;
        }
        if(!ans[i])
            ans[i]=x.first-(n-1-i);
        else
        ans[i]=min(ans[i],x.first-(n-1-i));
    }
    for(int i=0;i<n;i++)
        cout<<ans[i]<<" ";
    cout<<endl;

}

int main(){

fast;
int t=1;
cin>>t;
while(t--){
solve();

}

return 0;
}
