#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
priority_queue<pair<long long, long long>, vector<pair<long long, long long> >,
               greater<pair<long long, long long> > >
    pq;
vector<pair<long long, long long> > v[300000];
long long f[2][300000], n, m, start, dem, d[300000];
void init(long long t, long long k, long long l, long long r) {
  if (l == r) {
    f[t][k] = l;
    return;
  }
  long long mid = (l + r) / 2;
  dem++;
  f[t][k] = dem;
  init(t, k * 2, l, mid);
  init(t, k * 2 + 1, mid + 1, r);
  if (t == 0) {
    v[f[t][k]].push_back(make_pair(f[t][k * 2], 0));
    v[f[t][k]].push_back(make_pair(f[t][k * 2 + 1], 0));
  } else {
    v[f[t][k * 2]].push_back(make_pair(f[t][k], 0));
    v[f[t][k * 2 + 1]].push_back(make_pair(f[t][k], 0));
  }
}
void upd(long long t, long long k, long long l, long long r, long long ver,
         long long L, long long R, long long cost) {
  if (r < L || R < l || r < l) return;
  if (L <= l && r <= R) {
    if (t == 0)
      v[ver].push_back(make_pair(f[t][k], cost));
    else
      v[f[t][k]].push_back(make_pair(ver, cost));
    return;
  }
  long long mid = (l + r) / 2;
  upd(t, k * 2, l, mid, ver, L, R, cost);
  upd(t, k * 2 + 1, mid + 1, r, ver, L, R, cost);
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m >> start;
  dem = n;
  init(0, 1, 1, n);
  init(1, 1, 1, n);
  for (long long i = 0; i < m; i++) {
    long long t, x, y, l, r, cost;
    cin >> t;
    if (t == 1) {
      cin >> x >> y >> cost;
      v[x].push_back(make_pair(y, cost));
    } else {
      cin >> x >> l >> r >> cost;
      upd(t - 2, 1, 1, n, x, l, r, cost);
    }
  }
  for (long long i = 1; i <= dem; i++) d[i] = 1e17;
  d[start] = 0;
  pq.push(make_pair(0, start));
  while (!pq.empty()) {
    long long ver = pq.top().second;
    long long cost = pq.top().first;
    pq.pop();
    if (cost > d[ver]) continue;
    for (long long i = 0; i < v[ver].size(); i++) {
      long long ve = v[ver][i].first;
      long long cost = v[ver][i].second;
      if (d[ve] > d[ver] + cost)
        d[ve] = d[ver] + cost, pq.push(make_pair(d[ve], ve));
    }
  }
  for (long long i = 1; i <= n; i++) {
    if (d[i] == 1e17)
      cout << -1 << ' ';
    else
      cout << d[i] << ' ';
  }
}
