#include "bits/stdc++.h"
using namespace std;
#define ll long long

ll a[300007],b,c[300007],x[300007];
int main()
{
   int t,i,j;
   cin>>t;
   while(t--)
   {    
       int n,k;
       ll minn=10000000000,temp=0;
	   cin>>n>>k;
	   for(i=1;i<=n;i++) c[i]=0;
	   c[0]=10000000000;c[n+1]=10000000000;
	   for(i=0;i<=n;i++) x[i]=0;
       for(i=0;i<k;i++) cin>>a[i];
       for(i=0;i<k;i++)
       {
           cin>>x[a[i]];
       }
       for(i=1;i<=n;i++)
       {
           if(x[i])
           {
			   //cout<<minn<<" "<<temp<<endl;
               if(x[i]<=c[i-1]) 
               {
                   minn=x[i];
                   temp=i;
               }
           }
           c[i]=minn+i-temp;
       }
       minn=10000000000;
       for(i=n;i>0;i--)
       {
           if(x[i])
           {
               if(x[i]<=c[i+1])
               {
                   minn=x[i];
                   temp=i;
               }
           }
           c[i]=min(c[i],minn+temp-i);
       }
       for(i=1;i<=n;i++) cout<<c[i]<<" ";
       cout<<endl;
   }
   //system("pause");
}