#include <bits/stdc++.h>
using namespace std;
struct data {
  long long x, cost;
};
long long to[3500010 << 1], nxt[3500010 << 1], sum[3500010 << 1], head[3500010],
    in[500010 << 2], out[500010 << 2], cnt, nct, n, m, k, l, r, x, y, z, op,
    dis[3500010];
bool vis[3500010];
priority_queue<data> q;
bool operator<(data a, data b) { return a.cost > b.cost; }
void adde(long long x, long long y, long long w) {
  to[++nct] = y;
  nxt[nct] = head[x];
  sum[nct] = w;
  head[x] = nct;
}
void build(long long hao, long long l, long long r) {
  if (l == r) {
    in[hao] = out[hao] = l;
    return;
  }
  long long mid = (l + r) >> 1;
  build(hao << 1, l, mid);
  build(hao << 1 | 1, mid + 1, r);
  out[hao] = ++cnt;
  in[hao] = ++cnt;
  adde(out[hao << 1], out[hao], 0);
  adde(out[hao << 1 | 1], out[hao], 0);
  adde(in[hao], in[hao << 1], 0);
  adde(in[hao], in[hao << 1 | 1], 0);
}
void addein(long long hao, long long l, long long r, long long L, long long R,
            long long x, long long cost) {
  if (L <= l && R >= r) {
    adde(x, in[hao], cost);
    return;
  }
  long long mid = (l + r) >> 1;
  if (L <= mid) {
    addein(hao << 1, l, mid, L, R, x, cost);
  }
  if (R > mid) {
    addein(hao << 1 | 1, mid + 1, r, L, R, x, cost);
  }
}
void addeout(long long hao, long long l, long long r, long long L, long long R,
             long long x, long long cost) {
  if (L <= l && R >= r) {
    adde(out[hao], x, cost);
    return;
  }
  long long mid = (l + r) >> 1;
  if (L <= mid) {
    addeout(hao << 1, l, mid, L, R, x, cost);
  }
  if (R > mid) {
    addeout(hao << 1 | 1, mid + 1, r, L, R, x, cost);
  }
}
signed main() {
  scanf("%lld%lld%lld", &n, &m, &k);
  cnt = n;
  build(1, 1, n);
  for (long long i = 1; i <= m; i++) {
    scanf("%lld", &op);
    if (op == 1) {
      scanf("%lld%lld%lld", &x, &y, &z);
      adde(x, y, z);
    } else {
      if (op == 3) {
        scanf("%lld%lld%lld%lld", &x, &l, &r, &z);
        addeout(1, 1, n, l, r, x, z);
      } else {
        scanf("%lld%lld%lld%lld", &x, &l, &r, &z);
        addein(1, 1, n, l, r, x, z);
      }
    }
  }
  memset(dis, 127, sizeof(dis));
  dis[k] = 0;
  q.push((data){k, dis[k]});
  while (!q.empty()) {
    data u = q.top();
    q.pop();
    if (vis[u.x]) {
      continue;
    }
    vis[u.x] = 1;
    for (long long i = head[u.x]; i; i = nxt[i]) {
      long long v = to[i], w = sum[i];
      if (!v) {
        continue;
      }
      if (!vis[v] && w + u.cost < dis[v]) {
        data k;
        dis[v] = w + u.cost;
        k.cost = dis[v];
        k.x = v;
        q.push(k);
      }
    }
  }
  for (long long i = 1; i <= n; i++) {
    printf("%lld ", dis[i] == dis[0] ? -1 : dis[i]);
  }
  return 0;
}
