#include <bits/stdc++.h>
using namespace std;
const int N = 100007, M = 5000000;
const long long oo = 1000000000000000000;
int n, m, e, st, t, rt1, rt2, c, T[N], P[N], hd[N << 2], nt[M], to[M], go[M],
    B[N << 2], Ls[N << 3], Rs[N << 3];
long long D[N << 2];
void Add(int x, int y, int z) {
  nt[++e] = hd[x], hd[x] = e, to[e] = y, go[e] = z;
}
void Cook1(int &u, int l = 1, int r = n) {
  u = ++c;
  D[u] = oo;
  if (l == r) {
    P[l] = u;
    return;
  }
  int m = (l + r) >> 1;
  Cook1(Ls[u], l, m), Cook1(Rs[u], m + 1, r);
  Add(Ls[u], u, 0), Add(Rs[u], u, 0);
}
void Cook2(int &u, int l = 1, int r = n) {
  if (l == r) {
    u = P[l];
    return;
  }
  u = ++c;
  D[u] = oo;
  int m = (l + r) >> 1;
  Cook2(Ls[u], l, m), Cook2(Rs[u], m + 1, r);
  Add(u, Ls[u], 0), Add(u, Rs[u], 0);
}
void Get(int l, int r, int u, int L = 1, int R = n) {
  if (l == L && r == R) {
    T[++t] = u;
    return;
  }
  int m = (L + R) >> 1;
  if (r <= m)
    Get(l, r, Ls[u], L, m);
  else if (l > m)
    Get(l, r, Rs[u], m + 1, R);
  else
    Get(l, m, Ls[u], L, m), Get(m + 1, r, Rs[u], m + 1, R);
}
long long Qry(int x, int u = rt2, int l = 1, int r = n) {
  if (l == r) return D[u];
  int m = (l + r) >> 1;
  if (x <= m) return min(D[u], Qry(x, Ls[u], l, m));
  return min(D[u], Qry(x, Rs[u], m + 1, r));
}
struct _ {
  int x;
  long long y;
  bool operator<(const _ &_) const { return y > _.y; }
};
priority_queue<_> Q;
void Eat() {
  D[P[st]] = 0;
  Q.push((_){P[st], 0});
  while (!Q.empty()) {
    int u = Q.top().x;
    Q.pop();
    if (B[u]) continue;
    B[u] = 1;
    for (int i = hd[u]; i; i = nt[i])
      if (D[u] + go[i] < D[to[i]]) {
        D[to[i]] = D[u] + go[i];
        Q.push((_){to[i], D[to[i]]});
      }
  }
}
int main() {
  scanf("%d%d%d", &n, &m, &st);
  Cook1(rt1), Cook2(rt2);
  for (int i = 1; i <= m; ++i) {
    int o, x, y, u, w;
    scanf("%d", &o);
    if (o == 1) {
      scanf("%d%d%d", &x, &y, &w);
      Add(P[x], P[y], w);
    }
    if (o == 2) {
      scanf("%d%d%d%d", &u, &x, &y, &w);
      t = 0, Get(x, y, rt2);
      for (int i = 1; i <= t; ++i) Add(P[u], T[i], w);
    }
    if (o == 3) {
      scanf("%d%d%d%d", &u, &x, &y, &w);
      t = 0, Get(x, y, rt1);
      for (int i = 1; i <= t; ++i) Add(T[i], P[u], w);
    }
  }
  Eat();
  for (int i = 1; i <= n; ++i) {
    long long ans = Qry(i);
    printf("%lld ", ans >= oo ? -1 : ans);
  }
  return 0;
}
