#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)
#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)
#define EREP(i,u) for(int i=start[u];i;i=e[i].next)
#define fi first
#define se second
#define mkr(a,b) make_pair(a,b)
#define SZ(A) ((int)A.size())
template<class T>inline void chkmax(T &a,T b){ if(a<b)a=b;}
template<class T>inline void chkmin(T &a,T b){ if(a>b)a=b;}
inline int read()
{
    int s=0,f=1; char ch=getchar();
    while(!isdigit(ch) && ch!='-')ch=getchar();
    if(ch=='-')ch=getchar(),f=-1;
    while(isdigit(ch))s=s*10+ch-'0',ch=getchar();
    return ~f?s:-s;
}

const int maxn=2e5+20;
const ll inf=0x3f3f3f3f3f3f3f3f;

struct point {
    int x,y,id;
};
point p[maxn];
int ny[maxn],idy[maxn];
int to[maxn];

int n;

int l[maxn],r[maxn];

int sx[maxn];
int fa[maxn];
vector<int>ed[maxn]; int rd[maxn];

ll dp[maxn][2][2];

int rk[maxn],tp;
ll ans[maxn];

inline void get_rk()
{
    queue<int>q;
    REP(i,1,n)if(fa[i]==i && !rd[i])q.push(i);
    while(!q.empty())
    {
	int u=q.front();q.pop();
	rk[++tp]=u;
	for(int v:ed[u])
	    if(!(--rd[v]))
		q.push(v);
    }
}

inline void init()
{
    n=read();
    REP(i,1,n)p[i]=(point){read(),read(),i};
    sort(p+1,p+n+1,[](point a,point b){ return a.x<b.x;});
    REP(i,1,n)sx[i]=p[i].y; sort(sx+1,sx+n+1);
    REP(i,1,n)ny[i]=lower_bound(sx+1,sx+n+1,p[i].y)-sx,idy[ny[i]]=i;
    REP(i,1,n)fa[i]=i,l[i]=i,r[i]=i;
    REP(i,1,n)to[p[i].id]=i;
    REP(i,1,n-1)
    {
	if(abs(ny[i]-ny[i+1])==1)fa[i+1]=fa[i],r[fa[i+1]]=i+1;
	else {
	    int x=ny[i]+(ny[i]<ny[i+1]?1:-1);
	    if(idy[x]<i) ed[i+1].push_back(fa[i]),rd[fa[i]]++;
	    else ed[fa[i]].push_back(i+1),rd[i+1]++;
	}
    }
    DREP(i,n,1)l[i]=l[fa[i]],r[i]=r[fa[i]];
    get_rk();
}

inline int Dis(int i,int j){ return abs(p[j].x-p[i].x)+abs(p[j].y-p[i].y);}

inline void doing()
{
    REP(th,1,tp)
    {
	int u=rk[th];

	if(u==1)
	    u=1;
	
	int reml=l[u],remr=r[u];
	int &lx=l[u],&rx=r[u];
	
	dp[u][0][1]=l[u]==r[u]?0:Dis(l[u],r[u]);
	dp[u][1][0]=l[u]==r[u]?0:Dis(r[u],l[u]);
	dp[u][0][0]=dp[u][1][1]=inf;
	
	int L,R,ly,ry;
	ly=min(ny[lx],ny[rx]),ry=max(ny[lx],ny[rx]);
	
	do{
	    
	    int le=lx>1 && (ly-1==ny[lx-1] || ny[lx-1]==ry+1),re=rx<n && (ly-1==ny[rx+1] || ry+1==ny[rx+1]);
	    L=fa[lx-1],R=rx+1;
	    if(!le && !re)break;
	    if(le && re)
	    {
		static ll f[2][2]; memset(f,inf,sizeof(f));
		REP(st,0,1)REP(now,0,1)
		{
		    chkmin(f[st][0],dp[u][st][now]+Dis(now?rx:lx,rx+1)+dp[R][0][1]+Dis(r[rx+1],lx-1)+dp[L][1][0]);
		    chkmin(f[st][1],dp[u][st][now]+Dis(now?rx:lx,lx-1)+dp[L][1][0]+Dis(l[lx-1],rx+1)+dp[R][0][1]);
		}
		memcpy(dp[u],f,sizeof(f));
		chkmax(ry,max(ny[rx+1],ny[r[rx+1]]));
		chkmin(ly,min(ny[rx+1],ny[r[rx+1]]));
		chkmax(ry,max(ny[lx-1],ny[l[lx-1]]));
		chkmin(ly,min(ny[lx-1],ny[l[lx-1]]));
		lx=l[lx-1]; rx=r[rx+1];
		
	    }
	    else if(le)
	    {
		static ll f[2][2]; memset(f,inf,sizeof(f));
		REP(st,0,1)REP(now,0,1)
		{
		    chkmin(f[st][0],dp[u][st][now]+Dis(now?rx:lx,lx-1)+dp[L][1][0]);
		}
		memcpy(dp[u],f,sizeof(f));
		chkmax(ry,max(ny[lx-1],ny[l[lx-1]]));
		chkmin(ly,min(ny[lx-1],ny[l[lx-1]]));
		lx=l[lx-1];
	    }else
	    {
		static ll f[2][2]; memset(f,inf,sizeof(f));
		REP(st,0,1)REP(now,0,1)
		{
		    chkmin(f[st][1],dp[u][st][now]+Dis(now?rx:lx,rx+1)+dp[R][0][1]);
		}
		memcpy(dp[u],f,sizeof(f));
		chkmax(ry,max(ny[rx+1],ny[r[rx+1]]));
		chkmin(ly,min(ny[rx+1],ny[r[rx+1]]));
		rx=r[rx+1];
	    
	    }
	}while(1);
	REP(j,reml,remr)
	{
	    if(j==reml)ans[p[j].id]=min(dp[u][0][0],dp[u][0][1]);
	    else if(j==remr)ans[p[j].id]=min(dp[u][1][0],dp[u][1][1]);
	    else {
		ans[p[j].id]=inf;
		REP(op,0,1)chkmin(ans[p[j].id],min(dp[u][0][op]+Dis(j,reml),dp[u][1][op]+Dis(j,remr)));
	    }
	    ans[p[j].id]-=rx-lx;
	}
    }
    REP(i,1,n)printf("%lld\n",ans[i]);
}

int main()
{

    init();
    doing();
    return 0;
}


Measured memory_bytes: 31052