#include <bits/stdc++.h>
using namespace std;
const long long mk = 200055;
const long long logn = 29;
const long long mod = 1e9 + 7;
vector<pair<long long, long long> > g[4 * mk];
long long dis[4 * mk];
long long mvup[4 * mk], mvdown[4 * mk], k;
long long n, q, s;
void build(int id, int l, int r, int u, int v) {
  if (l > r || u > r || l > v) return;
  mvdown[id] = k++;
  mvup[id] = k++;
  if (l == r) {
    g[mvdown[id]].push_back({l, 0});
    g[l].push_back({mvup[id], 0});
    return;
  }
  int mid = (l + r) >> 1;
  build(id << 1, l, mid, u, v);
  build(id << 1 | 1, mid + 1, r, u, v);
  g[mvdown[id]].push_back({mvdown[id << 1], 0});
  g[mvdown[id]].push_back({mvdown[id << 1 | 1], 0});
  g[mvup[id << 1]].push_back({mvup[id], 0});
  g[mvup[id << 1 | 1]].push_back({mvup[id], 0});
}
void update(int id, int l, int r, int u, int v, int node, int val, int t) {
  if (l > r || u > r || l > v) return;
  if (u <= l && r <= v) {
    if (t == 2)
      g[node].push_back({mvdown[id], val});
    else
      g[mvup[id]].push_back({node, val});
    return;
  }
  int mid = (l + r) >> 1;
  update(id << 1, l, mid, u, v, node, val, t);
  update(id << 1 | 1, mid + 1, r, u, v, node, val, t);
}
void djk() {
  set<pair<long long, long long> > q;
  q.insert({0ll, s});
  dis[s] = 0ll;
  while (!q.empty()) {
    int u = q.begin()->second;
    q.erase(q.begin());
    for (int i = 0; i < g[u].size(); i++) {
      pair<long long, long long> t = g[u][i];
      int node = t.first;
      int edge = t.second;
      if (dis[node] > dis[u] + edge) {
        q.erase({dis[node], node});
        dis[node] = dis[u] + edge;
        q.insert({dis[node], node});
      }
    }
  }
}
void init() {
  cin >> n >> q >> s;
  for (int i = 1; i <= 4 * mk; i++) dis[i] = LLONG_MAX;
  k = n + 1;
  build(1, 1, n, 1, n);
  for (int i = 1; i <= q; i++) {
    int type, l, r, u, v, w;
    cin >> type;
    if (type == 1) {
      cin >> u >> v >> w;
      if (u != v) g[u].push_back({v, w});
    } else {
      cin >> u >> l >> r >> w;
      update(1, 1, n, l, r, u, w, type);
    }
  }
}
signed main() {
  init();
  djk();
  for (int i = 1; i <= n; i++) {
    if (dis[i] == LLONG_MAX) dis[i] = -1;
    cout << dis[i] << ' ';
  }
}
