#include <bits/stdc++.h>
using namespace std;
priority_queue<pair<long long, long long>, vector<pair<long long, long long> >,
               greater<pair<long long, long long> > >
    q;
stringstream ssin;
const long long LINF = 0x7fffffffffffffffll;
const long long N = 2e5 + 5, M = 5e6 + 5, mod = 1e9 + 7, INF = 0x3f3f3f3f;
long long n, m, st, idx, tot, rt1, rt2;
long long e[M], ne[M], h[M];
long long w[M], d[M];
bool vis[M];
struct node {
  long long l, r, ls, rs;
} tr1[N << 2], tr2[N << 2];
inline long long read() {
  char c = getchar();
  long long x = 0, f = 1;
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}
void add(int a, int b, long long c) {
  e[idx] = b;
  w[idx] = c;
  ne[idx] = h[a];
  h[a] = idx++;
}
void dij() {
  for (int i = 0; i < M; ++i) d[i] = 1e18;
  d[st] = 0;
  q.push({0, st});
  while (!q.empty()) {
    pair<long long, long long> t = q.top();
    q.pop();
    long long u = t.second;
    if (vis[u]) continue;
    vis[u] = 1;
    for (int i = h[u]; ~i; i = ne[i]) {
      long long v = e[i];
      long long z = w[i];
      if (d[u] + z < d[v]) {
        d[v] = d[u] + z;
        q.push({d[v], v});
      }
    }
  }
}
void build_in(long long &o, long long l, long long r) {
  if (l == r) {
    o = l;
    tr1[o].l = l;
    tr1[o].r = r;
    return;
  }
  o = ++tot;
  tr1[o].l = l;
  tr1[o].r = r;
  long long mid = l + r >> 1;
  build_in(tr1[o].ls, l, mid);
  build_in(tr1[o].rs, mid + 1, r);
  add(tr1[o].ls, o, 0);
  add(tr1[o].rs, o, 0);
}
void build_out(long long &o, long long l, long long r) {
  if (l == r) {
    o = l;
    tr2[o].l = l;
    tr2[o].r = r;
    return;
  }
  o = ++tot;
  tr2[o].l = l;
  tr2[o].r = r;
  long long mid = l + r >> 1;
  build_out(tr2[o].ls, l, mid);
  build_out(tr2[o].rs, mid + 1, r);
  add(o, tr2[o].ls, 0);
  add(o, tr2[o].rs, 0);
}
void upd2(long long o, long long l, long long r, long long u, long long z) {
  if (tr2[o].l >= l && tr2[o].r <= r) {
    add(u, o, z);
    return;
  }
  long long mid = tr2[o].l + tr2[o].r >> 1;
  if (mid >= l) upd2(tr2[o].ls, l, r, u, z);
  if (mid + 1 <= r) upd2(tr2[o].rs, l, r, u, z);
}
void upd1(long long o, long long l, long long r, long long u, long long z) {
  if (tr1[o].l >= l && tr1[o].r <= r) {
    add(o, u, z);
    return;
  }
  long long mid = tr1[o].l + tr1[o].r >> 1;
  if (mid >= l) upd1(tr1[o].ls, l, r, u, z);
  if (mid + 1 <= r) upd1(tr1[o].rs, l, r, u, z);
}
int main() {
  memset(h, -1, sizeof h);
  ;
  n = read();
  m = read();
  st = read();
  tot = n;
  build_in(rt1, 1, n);
  build_out(rt2, 1, n);
  while (m--) {
    long long op, u, v, l, r;
    long long z;
    op = read();
    if (op == 1) {
      u = read();
      v = read();
      z = read();
      add(u, v, z);
    } else {
      u = read();
      l = read();
      r = read();
      z = read();
      if (op == 2) {
        upd2(rt2, l, r, u, z);
      } else if (op == 3) {
        upd1(rt1, l, r, u, z);
      }
    }
  }
  dij();
  for (int i = 1; i <= n; ++i) cout << (d[i] == 1e18 ? -1 : d[i]) << " ";
  puts("");
}
