#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const long long INF = 1e18 + 9;
int n, q, s;
int type, u, v, l, r, mx = 0;
long long w;
vector<pair<int, long long> > adj[8 * N];
long long dist[8 * N];
int mp2[8 * N], mp3[8 * N];
priority_queue<pair<long long, int>, vector<pair<long long, int> >,
               greater<pair<long long, int> > >
    pq;
void build2(int id, int l, int r) {
  mx = max(mx, id);
  if (l == r) {
    mp2[l] = id;
    return;
  }
  int mid = (l + r) >> 1;
  build2(id << 1, l, mid);
  build2(id << 1 | 1, mid + 1, r);
  adj[id << 1].push_back({id, 0});
  adj[id << 1 | 1].push_back({id, 0});
}
void build3(int id, int l, int r) {
  if (l == r) {
    mp3[l] = id + mx;
    return;
  }
  int mid = (l + r) >> 1;
  build3(id << 1, l, mid);
  build3(id << 1 | 1, mid + 1, r);
  adj[id + mx].push_back({(id << 1) + mx, 0});
  adj[id + mx].push_back({(id << 1 | 1) + mx, 0});
}
void update(int id, int l, int r, int u, int L, int R, int w, int type) {
  if (l > R || L > r || l > r) return;
  if (L <= l && r <= R) {
    if (type == 2)
      adj[mp2[u]].push_back({id + mx, w});
    else
      adj[id].push_back({mp3[u], w});
    return;
  }
  int mid = (l + r) >> 1;
  update(id << 1, l, mid, u, L, R, w, type);
  update(id << 1 | 1, mid + 1, r, u, L, R, w, type);
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> q >> s;
  build2(1, 1, n);
  build3(1, 1, n);
  for (int i = 0; i < q; i++) {
    cin >> type;
    if (type == 1) {
      cin >> u >> v >> w;
      adj[mp2[u]].push_back({mp3[v], w});
    } else {
      cin >> u >> l >> r >> w;
      update(1, 1, n, u, l, r, w, type);
    }
  }
  for (int i = 1; i <= mx; i++) {
    adj[i + mx].push_back({i, 0});
  }
  for (int i = 0; i < 8 * N; i++) dist[i] = INF;
  dist[mp2[s]] = 0LL;
  pq.push({0LL, mp2[s]});
  while (!pq.empty()) {
    long long d = pq.top().first;
    int u = pq.top().second;
    pq.pop();
    if (d != dist[u]) continue;
    for (auto v : adj[u]) {
      if (dist[v.first] > dist[u] + v.second) {
        dist[v.first] = dist[u] + v.second;
        pq.push({dist[v.first], v.first});
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    int tmp_u = mp3[i];
    if (i == s)
      cout << 0 << ' ';
    else if (dist[tmp_u] == INF)
      cout << -1 << ' ';
    else
      cout << dist[tmp_u] << ' ';
  }
}
