#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e6 + 100, inf = 0x3f3f3f3f, MOD = 1e9 + 7;
const long long INF = 1e17 + 10;
struct node {
  int to;
  long long w;
  int next;
} edge[MAXN];
int cou, head[MAXN];
int Max;
int vis[MAXN];
long long ans[MAXN];
void init() {
  cou = 0;
  Max = 0;
  memset(vis, 0, sizeof(vis));
  memset(head, -1, sizeof(head));
}
void add(int u, int v, long long w) {
  cou++;
  edge[cou].to = v;
  edge[cou].w = w;
  edge[cou].next = head[u];
  head[u] = cou;
}
void build(int l, int r, int pos, int flag, int t) {
  if (t == 2) Max = max(Max, pos + flag);
  if (l == r) {
    if (t == 2)
      add(pos + flag, l, 0LL);
    else
      add(l, pos + flag, 0LL);
    return;
  }
  if (t == 2) {
    add(pos + flag, (pos << 1) + flag, 0LL);
    add(pos + flag, (pos << 1 | 1) + flag, 0LL);
  } else {
    add((pos << 1) + flag, pos + flag, 0LL);
    add((pos << 1 | 1) + flag, pos + flag, 0LL);
  }
  int mid = (l + r) >> 1;
  build(l, mid, pos << 1, flag, t);
  build(mid + 1, r, pos << 1 | 1, flag, t);
}
void update(int L, int R, long long w, int l, int r, int pos, int flag, int u,
            int t) {
  if (L <= l && r <= R) {
    if (t == 2)
      add(u, pos + flag, w);
    else
      add(pos + flag, u, w);
    return;
  }
  int mid = (l + r) >> 1;
  if (L <= mid) update(L, R, w, l, mid, pos << 1, flag, u, t);
  if (R > mid) update(L, R, w, mid + 1, r, pos << 1 | 1, flag, u, t);
}
struct mmp {
  int s;
  long long dis;
  mmp() {}
  mmp(long long ss, long long d) { s = ss, dis = d; }
  bool operator<(const mmp &x) const { return dis > x.dis; }
};
priority_queue<mmp> q;
void dij(int s) {
  ans[s] = 0LL;
  q.push(mmp(s, 0LL));
  while (!q.empty()) {
    mmp now = q.top();
    q.pop();
    int u = now.s;
    if (vis[u]) continue;
    vis[u] = 1;
    for (int i = head[u]; i != -1; i = edge[i].next) {
      int v = edge[i].to;
      long long w = edge[i].w;
      if (ans[v] > now.dis + w) {
        q.push(mmp(v, now.dis + w));
        ans[v] = now.dis + w;
      }
    }
  }
}
int main() {
  int n, q, s;
  scanf("%d%d%d", &n, &q, &s);
  init();
  build(1, n, 1, n + 1, 2);
  build(1, n, 1, Max + 1, 3);
  for (int i = 1; i <= q; i++) {
    int t;
    scanf("%d", &t);
    if (t == 1) {
      int u, v;
      long long w;
      scanf("%d%d%I64d", &u, &v, &w);
      add(u, v, w);
    } else {
      int u, l, r;
      long long w;
      scanf("%d%d%d%I64d", &u, &l, &r, &w);
      if (t == 2)
        update(l, r, w, 1, n, 1, n + 1, u, t);
      else
        update(l, r, w, 1, n, 1, Max + 1, u, t);
    }
  }
  for (int i = 0; i < MAXN; i++) ans[i] = INF;
  dij(s);
  for (int i = 1; i <= n; i++) {
    if (ans[i] >= INF)
      cout << "-1 ";
    else
      cout << ans[i] << " ";
  }
  cout << endl;
  return 0;
}
