#include <bits/stdc++.h>
using namespace std;
bool endline = false;
template <class T>
istream& operator>>(istream& inp, vector<T>& v) {
  for (auto& it : v) inp >> it;
  return inp;
}
template <class T>
ostream& operator<<(ostream& out, vector<T>& v) {
  for (auto& it : v) out << it << (endline ? "\n" : " ");
  return out;
}
template <class T, class U>
istream& operator>>(istream& inp, pair<T, U>& v) {
  inp >> v.first >> v.second;
  return inp;
}
template <class T, class U>
ostream& operator<<(ostream& out, pair<T, U>& v) {
  out << v.first << ' ' << v.second;
  return out;
}
void debug() { cout << endl; }
template <typename H, typename... T>
void debug(H a, T... b) {
  cout << a << ' ';
  debug(b...);
}
void FAST_IO(string filein = "", string fileout = "") {
  if (fopen(filein.c_str(), "r")) {
    freopen(filein.c_str(), "r", stdin);
    freopen(fileout.c_str(), "w", stdout);
  }
  cin.tie(0), cout.tie(0)->sync_with_stdio(0);
}
void Hollwo_Pelw();
signed main() {
  FAST_IO(".inp", ".out");
  int testcases = 1;
  for (int test = 1; test <= testcases; test++) {
    Hollwo_Pelw();
  }
  return 0;
}
const int allmod[3] = {(int)1e9 + 7, 998244353, (int)1e9 + 9};
const int mod = allmod[0];
const int MAXN = 1e5 + 5;
const int inf = 2e9;
const long long linf = 1e18;
vector<pair<long long, long long>> adj[MAXN * 9];
long long dist[MAXN * 9];
long long id[MAXN], add, n, q, s;
void build(long long node = 1, long long tl = 1, long long tr = n) {
  if (tl == tr) {
    long long idx = id[tl];
    adj[idx].emplace_back(node, 0);
    adj[node].emplace_back(idx, 0);
    adj[idx].emplace_back(node + add, 0);
    adj[node + add].emplace_back(idx, 0);
    return;
  }
  long long tm = (tl + tr) >> 1;
  build(node << 1, tl, tm);
  build(node << 1 | 1, tm + 1, tr);
  adj[node].emplace_back(node * 2, 0);
  adj[node * 2 + add].emplace_back(node + add, 0);
  adj[node].emplace_back(node * 2 + 1, 0);
  adj[node * 2 + 1 + add].emplace_back(node + add, 0);
}
void upd_2(long long u, long long l, long long r, long long w,
           long long node = 1, long long tl = 1, long long tr = n) {
  if (l > tr || r < tl) return;
  if (l <= tl && tr <= r) {
    adj[id[u]].emplace_back(node, w);
    return;
  }
  long long tm = (tl + tr) >> 1;
  upd_2(u, l, r, w, node << 1, tl, tm);
  upd_2(u, l, r, w, node << 1 | 1, tm + 1, tr);
}
void upd_3(long long u, long long l, long long r, long long w,
           long long node = 1, long long tl = 1, long long tr = n) {
  if (l > tr || r < tl) return;
  if (l <= tl && tr <= r) {
    adj[node + add].emplace_back(id[u], w);
    return;
  }
  long long tm = (tl + tr) >> 1;
  upd_3(u, l, r, w, node << 1, tl, tm);
  upd_3(u, l, r, w, node << 1 | 1, tm + 1, tr);
}
void dijk(long long s) {
  for (long long i = 1; i <= 9 * n; i++) {
    dist[i] = linf;
  }
  priority_queue<pair<long long, long long>, vector<pair<long long, long long>>,
                 greater<pair<long long, long long>>>
      pq;
  pq.push({dist[s] = 0, s});
  while (!pq.empty()) {
    auto [d, u] = pq.top();
    pq.pop();
    if (d != dist[u]) continue;
    for (auto [v, w] : adj[u]) {
      if (dist[v] > d + w) {
        pq.push({dist[v] = d + w, v});
      }
    }
  }
}
void Hollwo_Pelw() {
  cin >> n >> q >> s;
  for (long long i = 1; i <= n; i++) id[i] = i + 8 * n;
  add = 4 * n;
  build();
  while (q--) {
    long long t;
    cin >> t;
    if (t == 1) {
      long long u, v, w;
      cin >> u >> v >> w;
      adj[id[u]].emplace_back(id[v], w);
    } else {
      long long u, l, r, w;
      cin >> u >> l >> r >> w;
      if (t == 2) upd_2(u, l, r, w);
      if (t == 3) upd_3(u, l, r, w);
    }
  }
  dijk(id[s]);
  for (long long i = 1; i <= n; i++) {
    if (dist[id[i]] == linf) dist[id[i]] = -1;
    cout << dist[id[i]] << ' ';
  }
}
