#include <bits/stdc++.h>
using namespace std;
int n, q, s, t, u, v, l, r, node, st[2][1000005];
;
vector<long long int> d(1000005, (long long)1e15);
long long int w;
vector<pair<long long int, int> > adj[1000005];
void build(int i, int ss, int second) {
  if (ss > second) return;
  if (ss == second) {
    st[0][i] = st[1][i] = ss;
    return;
  }
  st[0][i] = (++node), st[1][i] = (++node);
  build(2 * i + 1, ss, (ss + second) / 2);
  build(2 * i + 2, 1 + (ss + second) / 2, second);
  adj[st[0][i]].push_back({0, st[0][2 * i + 1]}),
      adj[st[0][i]].push_back({0, st[0][2 * i + 2]});
  adj[st[1][2 * i + 1]].push_back({0, st[1][i]}),
      adj[st[1][2 * i + 2]].push_back({0, st[1][i]});
}
void connect(int i, int ss, int second) {
  if (ss > second or ss > r or second < l) return;
  if (ss >= l and second <= r) {
    if (t == 2)
      adj[v].push_back({w, st[0][i]});
    else
      adj[st[1][i]].push_back({w, v});
    return;
  }
  connect(2 * i + 1, ss, (ss + second) / 2);
  connect(2 * i + 2, 1 + (ss + second) / 2, second);
}
int main() {
  ios::sync_with_stdio(0);
  ;
  cin >> n >> q >> s;
  node = n;
  build(0, 1, n);
  while (q--) {
    cin >> t;
    if (t == 1) {
      cin >> u >> v >> w;
      adj[u].push_back({w, v});
    } else {
      cin >> v >> l >> r >> w;
      connect(0, 1, n);
    }
  }
  priority_queue<pair<long long int, int> > Q;
  d[s] = 0;
  Q.push({0, s});
  while (!Q.empty()) {
    int cheap = Q.top().second;
    Q.pop();
    for (pair<long long int, int> i : adj[cheap])
      if (d[i.second] > d[cheap] + i.first) {
        d[i.second] = d[cheap] + i.first;
        Q.push({-d[i.second], i.second});
      }
  }
  for (int i = 1; i <= n; i++) {
    if (d[i] == (long long)1e15)
      cout << "-1 ";
    else
      cout << d[i] << " ";
  }
}
