#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 4e18;
const int N = 5e5 + 1;
vector<int> vec;
vector<pair<int, ll> > g[N];
int n, op, t, l, r, q, s, pos[N][2];
void construct(int node = 1, int b = 1, int e = n) {
  pos[node][op] = ++t;
  if (b == e) {
    if (op == 0)
      g[pos[node][0]].push_back({b, 0});
    else
      g[b].push_back({pos[node][1], 0});
    return;
  }
  int m = (b + e) >> 1;
  construct(node << 1, b, m);
  construct(node << 1 | 1, m + 1, e);
  if (op == 0) {
    g[pos[node][0]].push_back({pos[node << 1][0], 0});
    g[pos[node][0]].push_back({pos[node << 1 | 1][0], 0});
  } else {
    g[pos[node << 1][1]].push_back({pos[node][1], 0});
    g[pos[node << 1 | 1][1]].push_back({pos[node][1], 0});
  }
}
void query(int node = 1, int b = 1, int e = n) {
  if (b > e || b > r || e < l) return;
  if (l <= b && e <= r) {
    vec.push_back(pos[node][op]);
    return;
  }
  int m = (b + e) >> 1;
  query(node << 1, b, m);
  query(node << 1 | 1, m + 1, e);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> q >> s;
  t = n;
  op = 0;
  construct();
  op = 1;
  construct();
  while (q--) {
    cin >> op;
    if (op == 1) {
      int v, u, w;
      cin >> v >> u >> w;
      g[v].push_back({u, w});
    } else {
      op -= 2;
      int v, w;
      cin >> v >> l >> r >> w;
      query();
      if (op == 0) {
        for (int x : vec) {
          g[v].push_back({x, w});
        }
      } else {
        for (int x : vec) {
          g[x].push_back({v, w});
        }
      }
      vec.clear();
    }
  }
  priority_queue<pair<ll, int> > pq;
  pq.push({0, s});
  vector<ll> dis(N, INF);
  dis[s] = 0;
  for (int i = 1; i <= n; i += 1) {
    pq.push({-dis[i], i});
  }
  while (!pq.empty()) {
    int u = pq.top().second;
    pq.pop();
    for (auto x : g[u]) {
      int v = x.first;
      int cost = x.second;
      if (dis[v] > dis[u] + cost) {
        dis[v] = dis[u] + cost;
        pq.push({-dis[v], v});
      }
    }
  }
  for (int i = 1; i <= n; i += 1) {
    if (dis[i] >= INF) dis[i] = -1;
    cout << dis[i] << ' ';
  }
  cout << '\n';
  return 0;
}
