#include <iostream>
#define INF 10000000000;
using ll = long long;
using namespace std;
void ac(ll n, ll arr[])
{
    ll L[n+2], R[n+2];
    ll air = INF;

    for(ll i = 0;i <n; i++)
    {
        air = min(air+1,arr[i]);
        L[i] = air;
    }

    air = INF;
    for(ll i = n-1; i>=0;i--)
    {
        air = min(air+1,arr[i]);
        R[i] = air;
    }

    for(ll i = 0; i<n;i++)
    {
        cout<<min(L[i],R[i])<<" ";
    }
    cout<<'\n';

}
int main()
{
   ll n,m,t;
   cin>>t;
   for(ll i = 0;i<t;i++)
   {
       cin>>n>>m;
       ll arr[n+2];
       for(ll i = 0; i<n+2;i++)
        arr[i] = INF;
       ll a[n+2];
           for(ll k = 0; k<m;k++)
            cin>>a[k];
           for(ll k = 0; k<m; k++)
            cin>>arr[a[k]-1];
       ac(n,arr);
   }
}