#include<bits/stdc++.h>
using namespace std;
typedef long long ll; 
typedef unsigned long long ull; 
typedef pair<int, int> pii; 
typedef pair<ll, ll> pll; 
typedef pair<string, string> pss; 
typedef pair<int, pii> piii;
typedef vector<pii> vii; 
typedef vector<int> vi; 
typedef vector<vi> vvi; 
typedef vector<vii> vvii; 
typedef vector<vvii> vvvii; 
typedef vector<pll> vll; 
typedef vector<ll> vl;
typedef vector<ull> vul; 
typedef vector<vl> vvl;
typedef vector<vll> vvll;

int main() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout); 
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL) ; cout.tie(NULL) ;
    ll ttt;
    cin>>ttt;
    // ttt=1;
    while(ttt--){
        int i,j,n,k;
        cin>>n>>k;
        vii conditioner(k);
        for(i=0;i<k;i++){
            cin>>j;
            conditioner[i].first=j-1;
        }
        for(i=0;i<k;i++){
            cin>>j;
            conditioner[i].second=j;
        }
        sort(conditioner.begin(), conditioner.end());
        // for(i=0;i<k;i++)cout<<conditioner[i].first<<"->"<<conditioner[i].second<<" ";cout<<endl;
        vi ans(n, 2e9);
        pii left={-1, -1}, right={-1, -1};
        j=0;
        for(i=0;i<n;i++){
            if(j<k && conditioner[j].first==i){
                if(left.first==-1 || left.second+i-left.first>conditioner[j].second)left=conditioner[j];
                j++;
            }
            if(left.first!=-1) ans[i]=min(ans[i], left.second+i-left.first);
            // cout<<left.first<<"->"<<left.second<<endl;
        }

        j=k-1;
        for(i=n-1;i>=0;i--){
            if(j>=0 && conditioner[j].first==i){
                if(right.first==-1 || right.second-i+right.first>conditioner[j].second)right=conditioner[j];
                j--;
            }
            if(right.first!=-1) ans[i]=min(ans[i], right.second+right.first-i);
        }

        for(i=0;i<n;i++)cout<<ans[i]<<" ";cout<<endl;

    }
    return 0;
}