#include <bits/stdc++.h>
using namespace std;
long long n, q, s, cnt, rt1, rt2;
long long fa[300005], ls[300005], rs[300005], tot;
long long L, R;
struct edge {
  long long v, w, nxt;
} edge[300005 * 20];
void addedge(int u, int v, int w) {
  edge[++tot].v = v, edge[tot].w = w, edge[tot].nxt = fa[u];
  fa[u] = tot;
}
void build1(long long &p, long long l, long long r) {
  if (l == r) {
    p = l;
    return;
  }
  p = ++cnt;
  long long mid = (l + r) >> 1;
  build1(ls[p], l, mid);
  build1(rs[p], mid + 1, r);
  addedge(p, ls[p], 0);
  addedge(p, rs[p], 0);
}
void build2(long long &p, long long l, long long r) {
  if (l == r) {
    p = l;
    return;
  }
  p = ++cnt;
  long long mid = (l + r) >> 1;
  build2(ls[p], l, mid);
  build2(rs[p], mid + 1, r);
  addedge(ls[p], p, 0);
  addedge(rs[p], p, 0);
}
void update(long long p, long long l, long long r, long long u, long long w,
            long long type) {
  if (L <= l && r <= R) {
    if (type == 2)
      addedge(u, p, w);
    else if (type == 3)
      addedge(p, u, w);
    return;
  }
  int mid = (l + r) >> 1;
  if (L <= mid) update(ls[p], l, mid, u, w, type);
  if (mid < R) update(rs[p], mid + 1, r, u, w, type);
}
long long dis[300005];
queue<long long> qu;
void findx(long long s) {
  memset(dis, 0x3F, sizeof(dis));
  dis[s] = 0;
  qu.push(s);
  while (!qu.empty()) {
    long long u = qu.front();
    qu.pop();
    for (long long i = fa[u]; i; i = edge[i].nxt) {
      long long v = edge[i].v, w = edge[i].w;
      if (dis[u] + w < dis[v]) {
        dis[v] = dis[u] + w;
        qu.push(v);
      }
    }
  }
}
int main() {
  scanf("%lld%lld%lld", &n, &q, &s);
  cnt = n;
  build1(rt1, 1, n);
  build2(rt2, 1, n);
  while (q--) {
    long long a, b, c, d, op;
    scanf("%lld", &op);
    if (op == 1) {
      scanf("%lld%lld%lld", &a, &b, &c);
      addedge(a, b, c);
    } else if (op == 2) {
      scanf("%lld%lld%lld%lld", &a, &L, &R, &b);
      update(rt1, 1, n, a, b, op);
    } else if (op == 3) {
      scanf("%lld%lld%lld%lld", &a, &L, &R, &b);
      update(rt2, 1, n, a, b, op);
    }
  }
  findx(s);
  for (long long i = 1; i <= n; i++) {
    if (dis[i] < 9999999999)
      printf("%lld ", dis[i]);
    else
      printf("-1 ");
  }
}
