#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 7;
const long long INF = 1LL << 60;
int n, m, s, op, v, x, y, c;
long long d[N << 1];
vector<int> g[N << 1], w[N << 1];
priority_queue<pair<long long, int>, vector<pair<long long, int>>,
               greater<pair<long long, int>>>
    q;
void add(int u, int v, int c) {
  g[u].push_back(v);
  w[u].push_back(c);
}
void build(int rt, int l, int r) {
  if (l == r) {
    add(rt + n, l, 0);
    add(l, N + rt + n, 0);
    return;
  }
  int mid = (l + r) >> 1, lc = rt << 1, rc = lc | 1;
  build(lc, l, mid), build(rc, mid + 1, r);
  add(rt + n, lc + n, 0), add(rt + n, rc + n, 0);
  add(N + lc + n, N + rt + n, 0), add(N + rc + n, N + rt + n, 0);
}
void update(int rt, int l, int r) {
  if (x <= l && r <= y) {
    if (op == 2)
      add(v, rt + n, c);
    else
      add(N + rt + n, v, c);
    return;
  }
  int mid = (l + r) >> 1, lc = rt << 1, rc = lc | 1;
  if (x <= mid) update(lc, l, mid);
  if (y > mid) update(rc, mid + 1, r);
}
void dij() {
  for (int i = 1; i < 2 * N; i++) d[i] = INF;
  d[s] = 0;
  q.push({d[s], s});
  while (q.size()) {
    pair<long long, int> t = q.top();
    q.pop();
    int u = t.second;
    if (d[u] < t.first) continue;
    for (int i = 0; i < g[u].size(); i++) {
      int v = g[u][i], c = w[u][i];
      if (d[v] > d[u] + c) {
        d[v] = d[u] + c;
        q.push({d[v], v});
      }
    }
  }
}
int main() {
  cin >> n >> m >> s;
  build(1, 1, n);
  for (int i = 0; i < m; i++) {
    scanf("%d", &op);
    if (op == 1) {
      scanf("%d%d%d", &x, &y, &c);
      add(x, y, c);
    } else {
      scanf("%d%d%d%d", &v, &x, &y, &c);
      update(1, 1, n);
    }
  }
  dij();
  for (int i = 1; i <= n; i++)
    if (d[i] == INF)
      printf("-1 ");
    else
      printf("%lld ", d[i]);
  return 0;
}
