#include <bits/stdc++.h>
using namespace std;
struct node {
  int p, l, r;
} tre[100010 << 2];
vector<pair<int, int> > e[100010 << 3];
const long long inf = 1e18;
int head[100010 << 1], a[100010 << 2], id[2][100010 << 2], vis[100010 << 3],
    idx, cnt, tot;
void add(int u, int v, int w) { e[u].push_back(make_pair(v, w)); }
void build(int p, int l, int r, bool flag) {
  id[flag][p] = ++idx;
  if (l == r) {
    if (flag)
      add(l, id[flag][p], 0);
    else
      add(id[flag][p], l, 0);
    return;
  }
  int mid = (l + r) >> 1;
  build(p << 1, l, mid, flag);
  build((p << 1) + 1, mid + 1, r, flag);
  if (flag) {
    add(id[flag][p << 1], id[flag][p], 0);
    add(id[flag][(p << 1) + 1], id[flag][p], 0);
  } else {
    add(id[flag][p], id[flag][p << 1], 0);
    add(id[flag][p], id[flag][(p << 1) + 1], 0);
  }
}
vector<int> v1;
long long d[100010 << 3];
void get(int nl, int nr, int p, int l, int r, int flag) {
  if (nl <= l && r <= nr) {
    v1.push_back(id[flag][p]);
    return;
  }
  int mid = (l + r) >> 1;
  if (nl <= mid) get(nl, nr, (p << 1), l, mid, flag);
  if (nr > mid) get(nl, nr, (p << 1) + 1, mid + 1, r, flag);
}
priority_queue<pair<long long, int> > q;
void Dij(int s) {
  for (int i = 1; i <= 100010 * 5; i++) vis[i] = 0, d[i] = inf;
  d[s] = 0;
  q.push(make_pair(0, s));
  while (!q.empty()) {
    int u = q.top().second;
    q.pop();
    if (vis[u]) continue;
    vis[u] = 1;
    for (int i = 0; i < e[u].size(); i++) {
      int v = e[u][i].first, c = e[u][i].second;
      if (d[v] > d[u] + c) d[v] = d[u] + c, q.push(make_pair(-d[v], v));
    }
  }
}
int main() {
  int n, q, s, op, u, v, w, l, r, i;
  scanf("%d %d %d", &n, &q, &s);
  idx = n;
  build(1, 1, n, 0);
  build(1, 1, n, 1);
  while (q--) {
    scanf("%d", &op);
    if (op == 1) scanf("%d%d%d", &u, &v, &w), add(u, v, w);
    if (op == 2) {
      v1.clear();
      scanf("%d%d%d%d", &u, &l, &r, &w);
      get(l, r, 1, 1, n, 0);
      for (i = 0; i < v1.size(); i++) add(u, v1[i], w);
    }
    if (op == 3) {
      v1.clear();
      scanf("%d%d%d%d", &u, &l, &r, &w);
      get(l, r, 1, 1, n, 1);
      for (i = 0; i < v1.size(); i++) add(v1[i], u, w);
    }
  }
  Dij(s);
  for (i = 1; i <= n; i++) {
    if (d[i] >= 1e18)
      printf("-1 ");
    else
      printf("%lld ", d[i]);
  }
}
