#include <bits/stdc++.h>
using namespace std;

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}
const int32 DIRECTED = 0;
const int32 UNDIRECTED = 1;

template<int32 isUNDIRECTED=0>
class Graph{
    struct Edge{
        int32 u, v, id;
        int64 c;
        Edge(int32 u, int32 v, int64 c=0, int32 id=0):u(u), v(v), c(c), id(id){}
    };

    int32 V, E;
    vector<vector<Edge>> G;
    vector<Edge> Es;
public:
    Graph(){}
    Graph(int32 V):V(V){G.resize(V);}
    Graph(const Graph<isUNDIRECTED>& g):V(g.V), E(g.E), G(g.G), Es(g.Es){}

    void add_edge(int32 u, int32 v, int64 c=0, int32 id=0){
        G[u].emplace_back(u, v, c, id);
        if(isUNDIRECTED) G[v].emplace_back(v, u, c, id);
        Es.emplace_back(u, v, c, id);
        E++;
    }

    const vector<Edge>& operator[](int32 k){
        return G[k];
    }

    int64 size() {
        return G.size();
    }
};

class SCC{
private:
    Graph<DIRECTED> orgG, revG, newG;
    vector<int32> ord, comp;
    vector<bool> used;
    vector<vector<int32>> vs;

    int32 V, nV;
public:
    SCC(){}
    SCC(int32 V):orgG(V), revG(V), comp(V, -1), used(V, 0), V(V){}

    void add_edge(int32 u, int32 v){
        orgG.add_edge(u, v);
        revG.add_edge(v, u);
    }

    void dfs(int32 v){
        used[v] = true;
        for(auto e : orgG[v]){
            if(!used[e.v]) dfs(e.v);
        }
        ord.push_back(v);
    }

    void rdfs(int32 v, int32 k){
        used[v] = true;
        comp[v] = k;
        for(auto e : revG[v]){
            if(!used[e.v]) rdfs(e.v, k);
        }
    }

    int32 build(){
        for(int32 i = 0;i < V;i++){
            if(!used[i]) dfs(i);
        }
        fill(used.begin(), used.end(), 0);
        int32 k = 0;
        for(int32 i = ord.size()-1;i >= 0;i--){
            if(!used[ord[i]]) rdfs(ord[i], k++);
        }
        nV = k;

        vs.resize(k, vector<int32>());
        for(int32 i = 0;i < V;i++)
            vs[comp[i]].push_back(i);

        newG = Graph<DIRECTED>(k);
        for(int32 i = 0;i < V;i++){
            for(auto e : orgG[i]){
                if(comp[i] != comp[e.v])
                    newG.add_edge(comp[i], comp[e.v], e.c);
            }
        }
        return k;
    }

    int32 size(){
        return nV;
    }
    int64 size(int64 v) {
        return vs[v].size();
    }

    const Graph<DIRECTED>& graph(){
        return newG;
    }

    const vector<int32>& vertices(int32 v){
        return vs[v];
    }

    int32 operator[](int32 k){
        return comp[k];
    }
};

int64 N, M;
vector<int64> x, y, z;
SCC scc;
Graph<DIRECTED> G;
vector<int64> res, used;
vector<vector<PLL>> D;

int64 dist(int64 a, int64 b) {
    return abs(x[a]-x[b]) + abs(y[a]-y[b]) + abs(z[a]-z[b]);
}

void dfs(int64 v) {
    if (used[v]) return;
    used[v] = 1;
    REP(i, G[v].size()) {
        dfs(G[v][i].v);
        REP(j, 8) {
            chmin(D[v][j], D[G[v][i].v][j]);
        }
    }
    auto vs = scc.vertices(v);
    REP(i, vs.size()) {
        REP(j, 8) {
            int64 nx = ((j & 1) ? -1 : 1) * x[vs[i]];
            int64 ny = ((j & 2) ? -1 : 1) * y[vs[i]];
            int64 nz = ((j & 4) ? -1 : 1) * z[vs[i]];
            chmin(D[v][j], PLL(nx+ny+nz, vs[i]));
        }
    }
    REP(i, vs.size()) {
        int64 vv = vs[i];
        REP(j, 8) {
            chmax(res[vv], dist(vv, D[v][j].sc));
        }
    }
}

int main(void) {
    cin >> N >> M;
    x.resize(N); y.resize(N); z.resize(N);
    REP(i, N) {
        cin >> x[i] >> y[i] >> z[i];
    }
    scc = SCC(N);
    REP(i, M) {
        int64 u, v;
        cin >> u >> v; u--; v--;
        scc.add_edge(u, v);
    }
    scc.build();
    res.resize(N, -1);
    used.resize(N, 0);
    G = scc.graph();
    D.resize(N, vector<PLL>(8, PLL(INF_LL, -1)));
    REP(i, N) {
        REP(j, 8) {
            int64 nx = ((j & 1) ? -1 : 1) * x[i];
            int64 ny = ((j & 2) ? -1 : 1) * y[i];
            int64 nz = ((j & 4) ? -1 : 1) * z[i];
        }
    }
    REP(i, scc.size()) {
        dfs(i);
    }
    REP(i, res.size()) {
        cout << res[i] << endl;
    }
}




Measured memory_bytes: 152804