#include <bits/stdc++.h>
using namespace std;
long long n, q, s;
long long e[800005];
long long rev[800005];
long long cnt;
vector<pair<long long, long long> > g[800005];
inline long long left(long long x) { return x << 1; }
inline long long right(long long x) { return (x << 1) + 1; }
void build(long long id, long long l, long long r) {
  if (l == r) {
    e[id] = l;
    rev[id] = r;
    return;
  }
  e[id] = ++cnt;
  rev[id] = ++cnt;
  long long mid = (l + r) >> 1;
  build(left(id), l, mid);
  build(right(id), mid + 1, r);
  g[e[id]].emplace_back(make_pair(e[left(id)], 0));
  g[e[id]].emplace_back(make_pair(e[right(id)], 0));
  g[rev[left(id)]].emplace_back(make_pair(rev[id], 0));
  g[rev[right(id)]].emplace_back(make_pair(rev[id], 0));
}
void qry(long long id, long long x, long long y, long long l, long long r,
         long long t, long long v, long long c) {
  if (x > r || y < l) return;
  if (l >= x && r <= y) {
    if (t == 2) {
      g[v].emplace_back(make_pair(e[id], c));
    } else {
      g[rev[id]].emplace_back(make_pair(v, c));
    }
    return;
  }
  long long mid = (l + r) >> 1;
  qry(left(id), x, y, l, mid, t, v, c);
  qry(right(id), x, y, mid + 1, r, t, v, c);
}
const long long inf = 1e16;
long long d[800005];
priority_queue<pair<long long, long long>, vector<pair<long long, long long> >,
               greater<pair<long long, long long> > >
    pq;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> q >> s;
  cnt = n;
  build(1, 1, n);
  while (q--) {
    long long t;
    cin >> t;
    if (t == 1) {
      long long u, v, c;
      cin >> u >> v >> c;
      if (u != v) {
        g[u].emplace_back(make_pair(v, c));
      }
    } else if (t == 2) {
      long long u, l, r, c;
      cin >> u >> l >> r >> c;
      qry(1, l, r, 1, n, t, u, c);
    } else {
      long long u, l, r, c;
      cin >> u >> l >> r >> c;
      qry(1, l, r, 1, n, t, u, c);
    }
  }
  for (long long i = 0; i < 800005; i++) d[i] = inf;
  d[s] = 0;
  pq.push(make_pair(0, s));
  while (pq.empty() == false) {
    long long D = pq.top().first;
    long long u = pq.top().second;
    pq.pop();
    if (d[u] < D) continue;
    for (auto i : g[u]) {
      long long nei = i.first;
      long long w = i.second;
      if (d[nei] > w + D) {
        d[nei] = w + D;
        pq.push(make_pair(d[nei], nei));
      }
    }
  }
  for (long long i = 1; i <= n; i++) {
    if (d[i] >= inf) d[i] = -1;
    cout << d[i] << " ";
  }
  return 0;
}
