#include <bits/stdc++.h>
using namespace std;
const long long int maxn = 1e5 + 5, M = 1e6 + 5, LG = 22, bghs = 1e9 + 7,
                    inf = 1e18 + 5, g2 = 5 * maxn;
vector<pair<long long int, long long int> > adj[10 * maxn];
long long int n, dist[10 * maxn];
set<pair<long long int, long long int> > se;
void build(long long int l = 0, long long int r = n, long long int id = 0) {
  if (r - l == 1) {
    adj[l].push_back(make_pair(g2 + id, 0));
    adj[maxn + id].push_back(make_pair(l, 0));
    return;
  }
  long long int mid = (r + l) >> 1;
  build(l, mid, 2 * id + 1);
  build(mid, r, 2 * id + 2);
  adj[id + maxn].push_back(make_pair(2 * id + 1 + maxn, 0));
  adj[id + maxn].push_back(make_pair(2 * id + 2 + maxn, 0));
  adj[2 * id + 1 + g2].push_back(make_pair(id + g2, 0));
  adj[2 * id + 2 + g2].push_back(make_pair(id + g2, 0));
}
void add(long long int v, long long int w, long long int s, long long int e,
         long long int t, long long int l = 0, long long int r = n,
         long long int id = 0) {
  if (e <= l || r <= s) return;
  if (s <= l && r <= e) {
    if (t == 1) {
      adj[v].push_back(make_pair(maxn + id, w));
    } else
      adj[g2 + id].push_back(make_pair(v, w));
    return;
  }
  long long int mid = (r + l) >> 1;
  add(v, w, s, e, t, l, mid, 2 * id + 1);
  add(v, w, s, e, t, mid, r, 2 * id + 2);
}
void dij(long long int s) {
  fill(dist, dist + 10 * maxn, inf);
  dist[s] = 0;
  se.insert(make_pair(0, s));
  while ((long long int)((se).size())) {
    long long int x = se.begin()->second;
    se.erase(se.begin());
    for (auto y : adj[x]) {
      long long int u = y.first, w = y.second;
      if (dist[u] <= dist[x] + w) continue;
      se.erase(make_pair(dist[u], u));
      dist[u] = dist[x] + w;
      se.insert(make_pair(dist[u], u));
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long int q, s;
  cin >> n >> q >> s;
  s--;
  build();
  while (q--) {
    long long int t;
    cin >> t;
    t--;
    if (t == 0) {
      long long int u, v, w;
      cin >> u >> v >> w;
      u--;
      v--;
      adj[u].push_back(make_pair(v, w));
    } else {
      long long int v, l, r, w;
      cin >> v >> l >> r >> w;
      v--;
      l--;
      add(v, w, l, r, t);
    }
  }
  dij(s);
  for (int i = 0; i < n; i++) cout << ((dist[i] == inf) ? -1 : dist[i]) << ' ';
}
