#include <bits/stdc++.h>
using namespace std;
const int N = 1000010;
const long long INF = 1e18;
vector<pair<int, int> > edges[N];
long long dst[N];
int SHIFT;
int SHIFT1, SHIFT2;
struct SegmentTree {
  void build(int v, int tl, int tr, int type) {
    if (tl == tr) {
      if (type == 2)
        edges[SHIFT + v].push_back({tl, 0});
      else
        edges[tl].push_back({SHIFT + v, 0});
      return;
    }
    int tm = (tl + tr) >> 1;
    build(v * 2, tl, tm, type);
    build(v * 2 + 1, tm + 1, tr, type);
    if (type == 2) {
      edges[SHIFT + v].push_back({SHIFT + v * 2, 0});
      edges[SHIFT + v].push_back({SHIFT + v * 2 + 1, 0});
    } else {
      edges[SHIFT + v * 2].push_back({SHIFT + v, 0});
      edges[SHIFT + v * 2 + 1].push_back({SHIFT + v, 0});
    }
  }
  void add(int v, int tl, int tr, int l, int r, int type, int u, int w) {
    if (l > r) {
      return;
    }
    if (tl == l && tr == r) {
      if (type == 2)
        edges[u].push_back({SHIFT + v, w});
      else
        edges[SHIFT + v].push_back({u, w});
      return;
    }
    int tm = (tl + tr) >> 1;
    add(v * 2, tl, tm, l, min(r, tm), type, u, w);
    add(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, type, u, w);
    return;
  }
} st;
void solve() {
  int n, q, s;
  cin >> n >> q >> s;
  SHIFT1 = n, SHIFT2 = 5 * n;
  SHIFT = SHIFT1;
  st.build(1, 1, n, 2);
  SHIFT = SHIFT2;
  st.build(1, 1, n, 3);
  while (q--) {
    int t;
    cin >> t;
    if (t == 1) {
      int v, u, w;
      cin >> v >> u >> w;
      edges[v].push_back({u, w});
    } else {
      int v, l, r, w;
      cin >> v >> l >> r >> w;
      SHIFT = (t == 2 ? SHIFT1 : SHIFT2);
      st.add(1, 1, n, l, r, t, v, w);
    }
  }
  fill(dst, dst + N, INF);
  dst[s] = 0;
  set<pair<long long, int> > st;
  st.insert({0, s});
  while (!st.empty()) {
    int v = st.begin()->second;
    st.erase(st.begin());
    for (auto [u, w] : edges[v]) {
      if (dst[u] > dst[v] + w) {
        st.erase({dst[u], u});
        dst[u] = dst[v] + w;
        st.insert({dst[u], u});
      }
    }
  }
  for (int v = 1; v <= n; v++) {
    cout << (dst[v] == INF ? -1 : dst[v]) << " ";
  }
}
int main() {
  ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
  cout.setf(ios::fixed), cout.precision(20);
  solve();
}
