#include <stack>
#include <algorithm>
#include <set>
#include <iostream>
#include <vector>
#include <random>
#include <utility>
using namespace std;
constexpr int INF = 1e9;

typedef pair<int, int> P;

struct StronglyConnectedComponents {
    int N;
    vector<vector<int> > g, gr, g2i;
    vector<bool> visited;
    vector<int> i2g;
    vector<P> edges;
    stack<int> st;

    StronglyConnectedComponents(){};
    StronglyConnectedComponents(int n){init(n);}
    void init(int n){
        N = n;
        g.clear();
        g.resize(n);
        gr.clear();
        gr.resize(n);
        edges.clear();
        visited.resize(n);
        i2g.resize(n);
    }
    void add_edge(int u, int v) {
        g[u].push_back(v);
        gr[v].push_back(u);
        edges.push_back(P(u, v));
    }

    void dfs(int x) {
        if (visited[x]) return;
        visited[x] = true;
        for (int i : g[x]) dfs(i);
        st.push(x);
    }

    void rdfs(int x, int k) {
        if (i2g[x] != -1) return;
        i2g[x] = k;
        for (int i : gr[x]) rdfs(i, k);
    }

    void build(vector<vector<int> > &t) {
        fill(visited.begin(), visited.end(), false);
        fill(i2g.begin(), i2g.end(), -1);
        for (int i = 0; i < N; i++) dfs(i);
        int p = 0;
        while (!st.empty()) {
            int v = st.top();
            st.pop();
            if (i2g[v] == -1) {
                rdfs(v, p);
                p++;
            }
        }
        g2i.clear();
        g2i.resize(p);
        t.resize(p);
        for(int i=0;i<N;i++){
            g2i[i2g[i]].push_back(i);
        }
        set<P> connected;
        for (auto &e : edges) {
            int x = i2g[e.first], y = i2g[e.second];
            if (x == y) continue;
            if (connected.count({x, y})) continue;
            t[x].push_back(y);
            connected.insert({x, y});
        }
    }
};

void dfs(const vector<vector<int>> &G, StronglyConnectedComponents &scc, int v, const vector<int> &W, vector<int> &ma){
  for(auto v_ : scc.g2i[v]){
    ma[v] = max(ma[v],W[v_]);
  }
  for(auto v_ : G[v]){
    if(ma[v_] == -INF){
      dfs(G,scc,v_,W,ma);
    }
    ma[v] = max(ma[v],ma[v_]);
  }
}

vector<int> solve2(const vector<vector<int>> &G, const vector<vector<int>> &G_, StronglyConnectedComponents &scc, const vector<int> &W){
  int M = G_.size();
  vector<int> ma(M,-INF);
  for(int i = 0; i < M; ++i){
    if(ma[i] <= -INF)
      dfs(G_,scc,i,W,ma);
  }
  int N = G.size();
  vector<int> A(N);
  for(int i = 0; i < N; ++i){
    int vv = scc.i2g[i];
    A[i] = ma[vv] - W[i];
  }
  return A;
}

vector<int> solve(const vector<vector<int>> &G, const vector<int> &X, const vector<int> &Y, const vector<int> &Z){
  int N = G.size();
  StronglyConnectedComponents scc(G.size());
  for(int i = 0; i < N; ++i){
    for(auto v : G[i]){
      scc.add_edge(i,v);
    }
  }
  vector<vector<int>> G_;
  scc.build(G_);
  int M = scc.g2i.size();
  vector<int> ans(N,-INF);
  for(int i = -1; i < 2; i += 2){
    for(int j = -1; j < 2; j += 2){
      for(int k = -1; k < 2; k += 2){
        vector<int> W(N), visited(N), ma(N,-INF);
        for(int l = 0; l < N; ++l){
          W[l] = i*X[l] + j*Y[l] + k*Z[l];
        }
        vector<int> A = solve2(G,G_,scc,W);
        for(int l = 0; l < N; ++l){
          ans[l] = max(ans[l],A[l]);
        }
      }
    }
  }
  return ans;
}

void dfs_naive(const vector<vector<int>> &G, const int v, set<int> &s){
  s.insert(v);
  for(auto v_ : G[v]){
    if(s.count(v_)) continue;
    dfs_naive(G,v_,s);
  }
}

vector<int> solve_naive(const vector<vector<int>> &G, const vector<int>& X, const vector<int>& Y, const vector<int> &Z){
  int N = G.size();
  vector<int> ret(N);
  for(int i = 0; i < N; ++i){
    set<int> s;
    dfs_naive(G,i,s);
    for(auto v : s){
      ret[i] = max(ret[i],abs(X[i]-X[v])+abs(Y[i]-Y[v])+abs(Z[i]-Z[v]));
    }
  }
  return ret;
}

void test(int N, int M){
  //int N = 4, M = 4;
  random_device rnd;
  vector<int> X(N), Y(N), Z(N);
  for(int i = 0; i < N; ++i){
    X[i] = rnd()%10;
    Y[i] = rnd()%10;
    Z[i] = rnd()%10;
  }
  set<pair<int,int>> S;
  vector<vector<int>> G(N);
  for(int i = 0; i < M; ++i){
    int u = rnd()%N, v = rnd()%N;
    while(u == v or S.count({u,v})){
      u = rnd()%N;
      v = rnd()%N;
    }
    G[u].push_back(v);
    S.insert({u,v});
  }
  vector<int> A = solve(G,X,Y,Z);
  return;
  vector<int> B = solve_naive(G,X,Y,Z);
  bool f = true;
  for(int i = 0; i < N; ++i){
    if(A[i] != B[i]){
      f = false;
      break;
    }
  }
  if(!f){
    cout << "Wrong Answer" << endl;
    cout << "solve : solve_naive" << endl;
    for(int i = 0; i < N; ++i){
      cout << A[i] << " " << B[i] << endl;
    }
    cout << "Test Case" << endl;
    cout << N << " " << M << endl;
    for(int i = 0; i < N; ++i)
      cout << X[i] << " " << Y[i] << " " << Z[i] << endl;
    for(int i = 0; i < N; ++i){
      for(auto v : G[i])
        cout << i+1 << " " << v+1 << endl;
    }
  }
}

int main(){
  int N, M;
  cin >> N >> M;
  // test(N,M);
  // return 0;
  vector<int> X(N), Y(N), Z(N);
  for(int i = 0; i < N; ++i){
    cin >> X[i] >> Y[i] >> Z[i];
  }
  vector<vector<int>> G(N);
  for(int i = 0; i < M; ++i){
    int u, v;
    cin >> u >> v;
    --u,--v;
    G[u].push_back(v);
  }
  vector<int> A = solve(G,X,Y,Z);
  for(auto a : A)
    cout << a << endl;
}



Measured memory_bytes: 91060