//#define NDEBUG
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

namespace n91 {

  using i8 = std::int_fast8_t;
  using i32 = std::int_fast32_t;
  using i64 = std::int_fast64_t;
  using u8 = std::uint_fast8_t;
  using u32 = std::uint_fast32_t;
  using u64 = std::uint_fast64_t;
  using isize = std::ptrdiff_t;
  using usize = std::size_t;

  constexpr usize operator"" _z(unsigned long long x) noexcept {
    return static_cast<usize>(x);
  }

  template <class T> class integral_iterator {
  public:
    using difference_type = T;
    using value_type = T;
    using pointer = const value_type*;
    using reference = value_type;
    using iterator_category = std::random_access_iterator_tag;

  private:
    using self_type = integral_iterator<value_type>;
    value_type i;

  public:
    constexpr integral_iterator() noexcept : i() {}
    explicit constexpr integral_iterator(const value_type i) noexcept : i(i) {}
    constexpr self_type operator++(int) noexcept { return self_type(i++); }
    constexpr self_type operator--(int) noexcept { return self_type(i--); }
    constexpr self_type operator[](const difference_type rhs) const noexcept {
      return self_type(i + rhs);
    }
    constexpr self_type& operator++() noexcept {
      ++i;
      return *this;
    }
    constexpr self_type& operator--() noexcept {
      --i;
      return *this;
    }
    constexpr reference operator*() const noexcept { return i; }
    constexpr self_type operator+(const difference_type rhs) const noexcept {
      return self_type(i + rhs);
    }
    constexpr self_type operator-(const difference_type rhs) const noexcept {
      return self_type(i - rhs);
    }
    constexpr difference_type operator-(const self_type rhs) const noexcept {
      return i - rhs.i;
    }
    constexpr bool operator<(const self_type rhs) const noexcept {
      return i < rhs.i;
    }
    constexpr bool operator<=(const self_type rhs) const noexcept {
      return i <= rhs.i;
    }
    constexpr bool operator>(const self_type rhs) const noexcept {
      return i > rhs.i;
    }
    constexpr bool operator>=(const self_type rhs) const noexcept {
      return i >= rhs.i;
    }
    constexpr bool operator==(const self_type rhs) const noexcept {
      return i == rhs.i;
    }
    constexpr bool operator!=(const self_type rhs) const noexcept {
      return i != rhs.i;
    }
    constexpr self_type& operator+=(const difference_type rhs) noexcept {
      i += rhs;
      return *this;
    }
    constexpr self_type& operator-=(const difference_type rhs) noexcept {
      i -= rhs;
      return *this;
    }
  };
  template <class T>
  constexpr integral_iterator<T> make_int_itr(const T i) noexcept {
    return integral_iterator<T>(i);
  }
  class rep {
    const usize f, l;

  public:
    constexpr rep(const usize f, const usize l) noexcept : f(f), l(l) {}
    constexpr auto begin() const noexcept { return make_int_itr(f); }
    constexpr auto end() const noexcept { return make_int_itr(l); }
  };
  class revrep {
    const usize f, l;

  public:
    revrep(const usize f, const usize l) noexcept : f(l), l(f) {}
    auto begin() const noexcept {
      return std::make_reverse_iterator(make_int_itr(f));
    }
    auto end() const noexcept {
      return std::make_reverse_iterator(make_int_itr(l));
    }
  };
  template <class T> auto md_vec(const usize n, const T& value) {
    return std::vector<T>(n, value);
  }
  template <class... Args> auto md_vec(const usize n, Args... args) {
    return std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
  }
  template <class T> constexpr T difference(const T& a, const T& b) {
    return a < b ? b - a : a - b;
  }
  template <class T> T scan() {
    T ret;
    std::cin >> ret;
    return ret;
  }

} // namespace n91

#include <cstdint>

namespace n91 {

  constexpr std::uint_fast64_t totient(std::uint_fast64_t x) noexcept {
    using u64 = std::uint_fast64_t;
    u64 ret = x;
    for (u64 i = static_cast<u64>(2); i * i <= x; ++i) {
      if (x % i == static_cast<u64>(0)) {
        ret -= ret / i;
        x /= i;
        while (x % i == static_cast<u64>(0)) {
          x /= i;
        }
      }
    }
    if (x != static_cast<u64>(1)) {
      ret -= ret / x;
    }
    return ret;
  }

  template <std::uint_fast64_t Modulus,
    std::uint_fast64_t InverseExp =
    totient(Modulus) - static_cast<std::uint_fast64_t>(1)>
    class modint {
    using u64 = std::uint_fast64_t;

    static_assert(Modulus < static_cast<u64>(1) << static_cast<u64>(32),
      "Modulus must be less than 2**32");

    u64 a;

    constexpr modint& negate() noexcept {
      if (a != static_cast<u64>(0)) {
        a = Modulus - a;
      }
      return *this;
    }

    public:
      constexpr modint(const u64 x = static_cast<u64>(0)) noexcept
        : a(x% Modulus) {}
      constexpr u64& value() noexcept { return a; }
      constexpr const u64& value() const noexcept { return a; }
      constexpr modint operator+() const noexcept { return modint(*this); }
      constexpr modint operator-() const noexcept { return modint(*this).negate(); }
      constexpr modint operator+(const modint rhs) const noexcept {
        return modint(*this) += rhs;
      }
      constexpr modint operator-(const modint rhs) const noexcept {
        return modint(*this) -= rhs;
      }
      constexpr modint operator*(const modint rhs) const noexcept {
        return modint(*this) *= rhs;
      }
      constexpr modint operator/(const modint rhs) const noexcept {
        return modint(*this) /= rhs;
      }
      constexpr modint& operator+=(const modint rhs) noexcept {
        a += rhs.a;
        if (a >= Modulus) {
          a -= Modulus;
        }
        return *this;
      }
      constexpr modint& operator-=(const modint rhs) noexcept {
        if (a < rhs.a) {
          a += Modulus;
        }
        a -= rhs.a;
        return *this;
      }
      constexpr modint& operator*=(const modint rhs) noexcept {
        a = a * rhs.a % Modulus;
        return *this;
      }
      constexpr modint& operator/=(modint rhs) noexcept {
        u64 exp = InverseExp;
        while (exp) {
          if (exp % static_cast<u64>(2) != static_cast<u64>(0)) {
            *this *= rhs;
          }
          rhs *= rhs;
          exp /= static_cast<u64>(2);
        }
        return *this;
      }
      constexpr bool operator==(const modint rhs) const noexcept {
        return a == rhs.a;
      }
      constexpr bool operator!=(const modint rhs) const noexcept {
        return a != rhs.a;
      }
  };

  template <class T, std::uint_fast64_t v> class modint_constant {
  public:
    static constexpr T value = static_cast<T>(v);

    using value_type = T;
  };

} // namespace n91

#include <functional>
#include <utility>

namespace n91 {

  template <class T, class U, class Operate = std::multiplies<T>>
  constexpr T power(T base, U exp, const Operate & oper = Operate(),
    T iden = static_cast<T>(1)) {
    while (exp != static_cast<U>(0)) {
      if (exp % static_cast<U>(2) != static_cast<U>(0)) {
        iden = oper(iden, base);
      }
      exp /= static_cast<U>(2);
      base = oper(base, base);
    }
    return iden;
  }

} // namespace n91

#include <vector>

namespace n91 {

  template <class T> class fact_binom {
  public:
    using value_type = T;
    using container_type = std::vector<value_type>;
    using size_type = typename container_type::size_type;

  private:
    container_type factrial, inv_fact;

  public:
    fact_binom() : factrial(), inv_fact() {}
    explicit fact_binom(const size_type n) : factrial(n + 1), inv_fact(n + 1) {
      factrial[0] = static_cast<value_type>(1);
      for (size_type i = 0; i != n; ++i) {
        factrial[i + 1] = static_cast<value_type>(i + 1) * factrial[i];
      }
      inv_fact[n] = static_cast<value_type>(1) / factrial[n];
      for (size_type i = n; i != 0; --i) {
        inv_fact[i - 1] = inv_fact[i] * static_cast<value_type>(i);
      }
    }

    value_type operator()(const size_type n, const size_type r) const {
      return factrial[n] * inv_fact[r] * inv_fact[n - r];
    }
  };

} // namespace n91


#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <utility>
#include<array>

namespace std {

  template <typename T> struct edge {
    int src, to;
    T cost;

    edge(int to, T cost) : src(-1), to(to), cost(cost) {}

    edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

    edge& operator=(const int& x) {
      to = x;
      return *this;
    }

    operator int() const { return to; }
  };

  template <typename T> using Edges = vector<edge<T>>;
  template <typename T> using WeightedGraph = vector<Edges<T>>;
  using UnWeightedGraph = vector<vector<int>>;
  template <typename T> using Matrix = vector<vector<T>>;

  template <typename G> struct StronglyConnectedComponents {
    const G& g;
    UnWeightedGraph gg, rg;
    vector<int> comp, order, used;

    StronglyConnectedComponents(G& g)
      : g(g), gg(g.size()), rg(g.size()), comp(g.size(), -1), used(g.size()) {
      for (int i = 0; i < g.size(); i++) {
        for (auto e : g[i]) {
          gg[i].emplace_back((int)e);
          rg[(int)e].emplace_back(i);
        }
      }
    }

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

    void dfs(int idx) {
      if (used[idx])
        return;
      used[idx] = true;
      for (int to : gg[idx])
        dfs(to);
      order.push_back(idx);
    }

    void rdfs(int idx, int cnt) {
      if (comp[idx] != -1)
        return;
      comp[idx] = cnt;
      for (int to : rg[idx])
        rdfs(to, cnt);
    }

    void build(UnWeightedGraph& t) {
      for (int i = 0; i < gg.size(); i++)
        dfs(i);
      reverse(begin(order), end(order));
      int ptr = 0;
      for (int i : order)
        if (comp[i] == -1)
          rdfs(i, ptr), ptr++;

      t.resize(ptr);
      for (int i = 0; i < g.size(); i++) {
        for (auto& to : g[i]) {
          int x = comp[i], y = comp[to];
          if (x == y)
            continue;
          t[x].push_back(y);
        }
      }
    }
  };

} // namespace std


namespace n91 {

  void main_() {
    const usize n = scan<usize>();
    const usize m = scan<usize>();
    struct planet {
      i64 x, y, z;
      i64 calc(usize i) const {
        return x * (i & 1 ? -1 : 1) + y * (i & 2 ? -1 : 1) + z * (i & 4 ? -1 : 1);
      }
      i64 dist(const planet& r) const {
        return std::abs(x - r.x) + std::abs(y - r.y) + std::abs(z - r.z);
      }
    };
    struct node {
      std::array<planet, 8> ps;
      void add(const node& r) {
        for (const auto i : rep(0_z, 8_z)) {
          if (ps[i].calc(i) < r.ps[i].calc(i)) {
            ps[i] = r.ps[i];
          }
        }
      }
      i64 dist(const planet& r) const {
        i64 ans = 0;
        for (const auto& e : ps) {
          ans = std::max(ans, r.dist(e));
        }
        return ans;
      }
      node() {}
      node(const planet& r) {
        for (auto& e : ps) {
          e = r;
        }
      }
    };
    std::vector<planet> p(n);
    for (auto& e : p) {
      std::cin >> e.x >> e.y >> e.z;
    }
    std::UnWeightedGraph g(n), buf;
    for (const auto i : rep(0_z, m)) {
      const usize u = scan<usize>() - 1_z;
      const usize v = scan<usize>() - 1_z;
      g[u].push_back(v);
    }
    std::StronglyConnectedComponents<std::UnWeightedGraph> scc(g);
    scc.build(buf);
    const usize k = buf.size();
    std::vector<std::vector<usize>> cs(k);
    for (const auto i : rep(0_z, n)) {
      cs[scc[i]].push_back(i);
    }
    std::vector<node> dp(k);
    std::vector<i64> ans(n);
    for (const auto ci : revrep(0_z, k)) {
      dp[ci] = node(p[cs[ci][0]]);
      for (const auto i : cs[ci]) {
        dp[ci].add(node(p[i]));
      }
      std::set<usize> set(buf[ci].begin(), buf[ci].end());
      for (const auto i : set) {
        dp[ci].add(dp[i]);
      }
      for (const auto i : cs[ci]) {
        ans[i] = dp[ci].dist(p[i]);
      }
    }
    for (const auto e : ans) {
      std::cout << e << std::endl;
    }
  }

} // namespace n91

int main() {
  n91::main_();
  return 0;
}



Measured memory_bytes: 105952