#include <cstdio> 
#include <vector>
#include <climits>
#include <algorithm>
#include <functional> 
using namespace std;

struct Rook {
    int x, y, id;
    bool operator <(const Rook& other) const {
        return x < other.x;
    }
};

long long hack;

template<class C>
void min_self (C &a, C &&b) {
    a = min(a, b);
};

int main() {
    int n;
    scanf("%d", &n);
    vector<Rook> rooks(n);
    for(int i = 0; i < n; ++i) {
        rooks[i].id = i;
        scanf("%d%d", &rooks[i].x, &rooks[i].y);
    }
    sort(rooks.begin(), rooks.end());
    vector<int> ys{INT_MIN, INT_MAX}; // two sentinels for convenience
    for(int i = 0; i < n; ++i) {
        ys.push_back(rooks[i].y);
    }
    sort(ys.begin(), ys.end());
    vector< pair<long long, long long> > answer(n, {-1, -1});
    for(int start = 0; start < n; ++start) {
        if(answer[rooks[start].id].first != -1) {
            continue;
        }

        int start_y = lower_bound(ys.begin(), ys.end(), rooks[start].y) - ys.begin();
        int y1 = start_y - 1, y2 = start_y + 1;

        int L = start, R = start;
        int prev_dir = -1;
        vector< pair<int, int> > intervals;
        while(true) {
            bool found = false;
            for(int i : {L - 1, R + 1}) {
                if(0 <= i && i < n) {
                    bool prev_y = (ys[y1] == rooks[i].y);
                    bool next_y = (ys[y2] == rooks[i].y);
                    if(prev_y || next_y) {
                        int direction = (prev_y == (i == L - 1));
                        if(prev_dir == -1) {
                            prev_dir = direction;
                        }
                        if(prev_dir != direction) {
                            intervals.emplace_back(L, R);
                            prev_dir = direction;
                        }
                        prev_y ? y1-- : y2++;
                        i == L-1 ? L-- : R++;
                        found = true;
                        break;
                    }
                }
            }
            if(!found) {
                break;
            }
        }
        if(intervals.empty() || intervals.back() != make_pair(L, R)) {
            intervals.emplace_back(L, R);
        }
        const int s = intervals.size();

        const long long INF = 1e18L + 5;
        
        auto f = [&] (int i, int j) {
            return abs(rooks[i].x - rooks[j].x) + abs(rooks[i].y - rooks[j].y);
        };
        
        vector< vector<long long> > dp(s, vector<long long>(2, INF));
        dp[s-1][0] = dp[s-1][1] = 0;
        for(int who = s - 1; who >= 1; --who) {
            int L1 = intervals[who].first;
            int L2 = intervals[who-1].first;
            int R1 = intervals[who-1].second;
            int R2 = intervals[who].second;
            hack += (long long) (L2 - L1) * (R2 - R1);
            min_self(dp[who-1][0], dp[who][0] + (R1 == R2 ? f(L1, L2) : f(L1, R2) + f(R2, L2)));
            min_self(dp[who-1][1], dp[who][0] + f(L1, R2) + f(R2, R1));
            min_self(dp[who-1][0], dp[who][1] + f(R2, L1) + f(L1, L2));
            min_self(dp[who-1][1], dp[who][1] + (L1 == L2 ? f(R1, R2) : f(R2, L1) + f(L1, R1)));
        }
        int low = intervals[0].first, high = intervals[0].second;
        for(int i = low; i <= high; ++i) {
            answer[rooks[i].id] = {
                R - L,
                min(dp[0][0] + f(low, high) + f(high, i), dp[0][1] + f(high, low) + f(low, i))
            };
        }
    }
    for(auto p : answer) {
        printf("%lld\n", p.second - p.first);
    }
}

Measured memory_bytes: 20708