import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;


void main() {
    int N;
    scan(N);
    auto adj = new int[][](N, 0);
    foreach (i ; 0 .. N - 1) {
        int ai, bi;
        scan(ai, bi);
        ai--, bi--;
        adj[ai] ~= bi;
        adj[bi] ~= ai;
    }

    auto c = new int[](N);

    int dfs(int v, int p, int pp) {
        int cs;
        foreach (u ; adj[v]) if (u != p) {
            cs += adj[u].length.to!int - 1;
        }
        foreach (u ; adj[v]) if (u != p) {
            if (pp != -1) c[u]++;
            if (p != -1) {
                int d = adj[p].length.to!int - 2;
                c[u] += d;
            }
            c[u] += cs - (adj[u].length.to!int - 1);
            c[v] += dfs(u, v, p);
        }
        return cs;
    }

    dfs(0, -1, -1);

    auto div = new int[][](3, 0);
    foreach (i ; 1 .. N + 1) {
        div[i % 3] ~= i;
    }

    debug {
        writeln(div);
        writeln(div[2]);
    }

    auto p = new int[](N);
    p[] = -1;

    foreach (i ; 0 .. N) {
        if (c[i] > (N - 1) - (N / 3)) {
            if (div[0].empty) {
                writeln(-1);
                return;
            }
            p[i] = div[0].front;
            div[0].popFront();
        }
    }

    bool col(int v, int par, int nm) {
        if (p[v] == -1) {
            debug {
                writeln(nm);
                writeln(div);
                writeln(div[nm]);
            }
            if (!div[nm].empty) {
                p[v] = div[nm].front;
                div[nm].popFront();
            }
            else {
                if (!div[0].empty) {
                    p[v] = div[0].front;
                    div[0].popFront();
                }
                else {
                    return false;
                }
            }
        }

        auto e = true;

        foreach (u ; adj[v]) if (u != par) {
            //int nn = (nm == 1 ? 2 : 1);
            e &= col(u, v, nm == 1 ? 2 : 1);
        }

        return e;
    }

    auto e = col(0, -1, 1);

    if (!e) {
        writeln(-1);
        return;
    }

    writefln("%(%s %)", p);
}




void scan(T...)(ref T args) {
    auto line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x > arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x < arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}



