#include <bits/stdc++.h>
#define forn(i, n) for (long long i = 0; i < n; i++)
#define forvn(i, v, n) for (long long i = v; i < n; i++)
#define forn1(i,n) for (long long i = 1; i <=n; i++)
#define ll long long
#define pii pair<int, int>
#define pll pair<long long, long long>
#define coutln cout << "\n"
#define coutfor(arr, n) for (int i = 0; i < n; i++) cout << arr[i] << " ";
#define all(v) (v).begin(), (v).end()
#define INF 1000000007
ll gcd(ll a, ll b) { return a % b ? gcd(b, a % b) : b; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }
ll xx[4] = {1, 0, -1, 0}, yy[4] = {0, 1, 0, -1};
using namespace std;

ll pos[300010];
ll le[300010],ri[300010];

void solve()
{
	ll n,k;
	cin >> n >> k;
	fill(le,le+n+1,1e10);
	fill(ri,ri+n+1,1e10);
	forn(i,k)
	{
		cin >> pos[i];
	}
	forn(i,k)
	{
		ll tem;
		cin >> tem;
		le[pos[i]] = ri[pos[i]] = tem;
	}
	int pnt = 1;
	ll curTem = ri[1];
	while(pnt<=n)
	{
		if(curTem > ri[pnt])
		{
			curTem = ri[pnt];
		}
		ri[pnt] = curTem;
		curTem++;
		pnt++;
	}

	pnt = n;
	curTem = le[n];
	while(pnt>=1)
	{
		if(curTem > le[pnt])
		{
			curTem = le[pnt];
		}
		le[pnt] = curTem;
		curTem++;
		pnt--;
	}
	for(int i=1;i<=n;i++)
	{
		cout << min(le[i],ri[i]) << " ";
	}
	cout << "\n";
}

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int t = 1;
	cin >> t;
	while(t--)
	{
		solve();
	}
}
