#include <bits/stdc++.h>
using namespace std;
priority_queue<pair<long long, int> > q;
int head[100010 << 5], to[150001 << 5], nxt[150001 << 5], cnt, ls[100010 << 5],
    rs[100010 << 5], ra, rb, tot, v[100010 << 5], n, vis[150001 << 5];
long long len[150001 << 5], dis[100010 << 5];
void add(int x, int y, long long z) {
  to[++cnt] = y, len[cnt] = z, nxt[cnt] = head[x], head[x] = cnt;
}
void build(int l, int r, int &x, int flag) {
  x = ++tot;
  if (l == r) {
    if (flag) v[l] = x;
    return;
  }
  int mid = (l + r) >> 1;
  build(l, mid, ls[x], flag), build(mid + 1, r, rs[x], flag);
  if (flag)
    add(ls[x], x, 0), add(rs[x], x, 0);
  else
    add(x, ls[x], 0), add(x, rs[x], 0);
}
void deal(int l, int r, int x, int y) {
  if (l == r) {
    add(y, x, 0);
    return;
  }
  int mid = (l + r) >> 1;
  deal(l, mid, ls[x], ls[y]), deal(mid + 1, r, rs[x], rs[y]);
}
void update(int b, int e, int p, int l, int r, int x, int flag) {
  if (b <= l && r <= e) {
    if (flag)
      add(x, p, 0);
    else
      add(p, x, 0);
    return;
  }
  int mid = (l + r) >> 1;
  if (b <= mid) update(b, e, p, l, mid, ls[x], flag);
  if (e > mid) update(b, e, p, mid + 1, r, rs[x], flag);
}
void link(int a, int b, int c, int d, long long w) {
  update(a, b, ++tot, 1, n, ra, 1), add(tot, tot + 1, w),
      update(c, d, ++tot, 1, n, rb, 0);
}
int main() {
  int m, p, a, b, c, i, x;
  long long d;
  scanf("%d%d%d", &n, &m, &p);
  build(1, n, ra, 1), build(1, n, rb, 0), deal(1, n, ra, rb);
  for (i = 1; i <= m; i++) {
    int op;
    scanf("%d", &op);
    if (op == 1) {
      scanf("%d%d%lld", &a, &b, &d), link(a, a, b, b, d);
    } else if (op == 2) {
      scanf("%d%d%d%lld", &a, &b, &c, &d), link(a, a, b, c, d);
    } else {
      scanf("%d%d%d%lld", &a, &b, &c, &d), link(b, c, a, a, d);
    }
  }
  memset(dis, 0x7f7f7f7f7f7f7f7f, sizeof(dis)), dis[v[p]] = 0,
                                                q.push(make_pair(0, v[p]));
  while (!q.empty()) {
    x = q.top().second, q.pop();
    if (vis[x]) continue;
    vis[x] = 1;
    for (i = head[x]; i; i = nxt[i])
      if (dis[to[i]] > dis[x] + len[i])
        dis[to[i]] = dis[x] + len[i], q.push(make_pair(-dis[to[i]], to[i]));
  }
  for (i = 1; i <= n; i++)
    if (dis[v[i]] != 0x7f7f7f7f7f7f7f7f)
      printf("%lld ", dis[v[i]]);
    else
      printf("-1 ");
  return 0;
}
