#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<map>
#include<cmath>
#define int long long
using namespace std;
int t,n,m,ans[300005],now[300005];
struct node{
	int x,y;
}a[300005];
bool cmp(node q,node w){
	return q.y<w.y;
}
signed main(){
	scanf("%lld",&t);
	while(t--){
		scanf("%lld%lld",&n,&m);
		for(int i=1;i<=m;i++)scanf("%lld",&a[i].x);
		for(int i=1;i<=m;i++)scanf("%lld",&a[i].y);
		for(int i=0;i<=max(n,m)+3;i++)ans[i]=now[i]=1e18;
		for(int i=1;i<=m;i++)now[a[i].x]=a[i].y;
		int sum=1e18;
		for(int i=1;i<=n;i++)sum=min(sum+1,now[i]),ans[i]=sum;
		sum=1e18;
		for(int i=n;i>=1;i--)sum=min(sum+1,now[i]),ans[i]=min(ans[i],sum);
		for(int i=1;i<=n;i++)printf("%lld ",ans[i]);
		printf("\n");
	}
}