#include <bits/stdc++.h>
using namespace std;
long long n, t, s, f[5000001], numedge, vis[5000001], head[5000001],
    vis1[5000001], vis2[5000001];
struct edge {
  long long next, to, data;
} ed[2500001];
struct node {
  long long to, data;
  bool operator<(const node &a) const { return data > a.data; }
};
priority_queue<node> q;
void addedge(long long x, long long y, long long z) {
  ed[++numedge] = (edge){head[x], y, z};
  head[x] = numedge;
}
void build(long long o, long long l, long long r) {
  if (l == r) {
    vis1[l] = o;
    vis2[l] = o + 4 * n;
    addedge(o, o + 4 * n, 0);
    addedge(o + 4 * n, o, 0);
    return;
  }
  long long mid = (l + r) >> 1;
  build(o << 1, l, mid);
  build(o << 1 | 1, mid + 1, r);
  addedge(o, o << 1, 0);
  addedge(o, o << 1 | 1, 0);
  addedge((o << 1) + 4 * n, o + 4 * n, 0);
  addedge((o << 1 | 1) + 4 * n, o + 4 * n, 0);
}
void dijskstra() {
  q.push((node){vis1[s], 0});
  memset(f, 0x3f, sizeof(f));
  f[vis1[s]] = 0;
  while (!q.empty()) {
    node x = q.top();
    q.pop();
    if (vis[x.to]) continue;
    vis[x.to] = 1;
    for (long long i = head[x.to]; i; i = ed[i].next) {
      if (f[x.to] + ed[i].data <= f[ed[i].to]) {
        f[ed[i].to] = f[x.to] + ed[i].data;
        q.push((node){ed[i].to, f[ed[i].to]});
      }
    }
  }
}
void add(long long o, long long l, long long r, long long ql, long long qr,
         long long x, long long k, long long d) {
  if (ql <= l && r <= qr) {
    if (!d)
      addedge(vis2[x], o, k);
    else
      addedge(o + 4 * n, vis1[x], k);
    return;
  }
  long long mid = (l + r) >> 1;
  if (ql <= mid) add(o << 1, l, mid, ql, qr, x, k, d);
  if (mid < qr) add(o << 1 | 1, mid + 1, r, ql, qr, x, k, d);
}
signed main() {
  scanf("%lld%lld%lld", &n, &t, &s);
  build(1, 1, n);
  for (long long i = 1; i <= t; i++) {
    long long opt, u, v, l, r, w;
    scanf("%lld", &opt);
    if (opt == 1)
      scanf("%lld%lld%lld", &v, &u, &w), addedge(vis1[v], vis1[u], w);
    if (opt == 2)
      scanf("%lld%lld%lld%lld", &v, &l, &r, &w), add(1, 1, n, l, r, v, w, 0);
    if (opt == 3)
      scanf("%lld%lld%lld%lld", &v, &l, &r, &w), add(1, 1, n, l, r, v, w, 1);
  }
  dijskstra();
  for (long long i = 1; i <= n; i++) {
    if (f[vis1[i]] != f[0])
      printf("%lld ", f[vis1[i]]);
    else
      printf("-1 ");
  }
}
