#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 2e6 + 100;
long long n, m, s;
struct Edge {
  long long u, v, w, Next;
} edge[MAXN * 2];
long long tot;
long long head[MAXN];
void init() {
  tot = 0;
  memset(head, -1, sizeof(head));
}
void addedge(long long u, long long v, long long w) {
  edge[tot].u = u;
  edge[tot].v = v;
  edge[tot].w = w;
  edge[tot].Next = head[u];
  head[u] = tot++;
}
long long cnt;
long long num[MAXN];
void getid(long long id, long long l, long long r) {
  if (l == r) {
    num[l] = id;
    return;
  }
  cnt += 2;
  getid((id * 2), l, ((l + r) / 2));
  getid((id * 2 + 1), ((l + r) / 2) + 1, r);
}
void add(long long id, long long l, long long r) {
  if (l == r) return;
  add((id * 2), l, ((l + r) / 2));
  add((id * 2 + 1), ((l + r) / 2) + 1, r);
  addedge(id, (id * 2), 0);
  addedge(id, (id * 2 + 1), 0);
  addedge((id * 2) + cnt, id + cnt, 0);
  addedge((id * 2 + 1) + cnt, id + cnt, 0);
}
void update(long long id, long long l, long long r, long long ql, long long qr,
            long long tt, long long x, long long w) {
  if (ql <= l && r <= qr) {
    if (!tt)
      addedge(num[x] + cnt, id, w);
    else
      addedge(id + cnt, num[x], w);
    return;
  }
  if (ql <= ((l + r) / 2)) update((id * 2), l, ((l + r) / 2), ql, qr, tt, x, w);
  if (((l + r) / 2) + 1 <= qr)
    update((id * 2 + 1), ((l + r) / 2) + 1, r, ql, qr, tt, x, w);
  return;
}
long long low[MAXN];
struct node {
  long long x, d;
  bool operator<(const node &a) const {
    if (d == a.d)
      return x < a.x;
    else
      return d > a.d;
  }
};
void dijkstra() {
  memset(low, -1, sizeof(low));
  low[num[s]] = 0;
  priority_queue<node> q;
  q.push((node){num[s], low[num[s]]});
  while (!q.empty()) {
    node u = q.top();
    q.pop();
    for (long long i = head[u.x]; i != -1; i = edge[i].Next) {
      long long v = edge[i].v;
      long long w = edge[i].w;
      if (low[v] == -1 || low[v] > u.d + w) {
        low[v] = u.d + w;
        q.push((node){v, low[v]});
      }
    }
  }
  for (long long i = 1; i <= n; i++) {
    printf("%lld ", low[num[i]]);
  }
}
int main() {
  init();
  scanf("%lld%lld%lld", &n, &m, &s);
  int tmp = n;
  cnt = 1;
  while (tmp) tmp /= 2, cnt *= 2;
  getid(1, 1, n);
  add(1, 1, n);
  for (long long i = 1; i <= n; i++) addedge(num[i], num[i] + cnt, 0);
  while (m--) {
    long long op;
    scanf("%lld", &op);
    if (op == 1) {
      long long u, v, w;
      scanf("%lld%lld%lld", &u, &v, &w);
      addedge(num[u] + cnt, num[v], w);
    } else if (op == 2) {
      long long x, l, r, w;
      scanf("%lld%lld%lld%lld", &x, &l, &r, &w);
      update(1, 1, n, l, r, 0, x, w);
    } else {
      long long x, l, r, w;
      scanf("%lld%lld%lld%lld", &x, &l, &r, &w);
      update(1, 1, n, l, r, 1, x, w);
    }
  }
  dijkstra();
  return 0;
}
