#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization(l "unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const long long MAX = 1 << 17;
const long long inf = 1e18 + 9;
vector<pair<long long, long long> > P[MAX * 10];
long long dp[MAX * 10];
pair<long long, long long> t1[MAX * 2];
pair<long long, long long> t2[MAX * 2];
void add_edge(long long a, long long b, long long c) {
  P[a].push_back(make_pair(b, c));
}
void add1(long long l, long long r, long long u, long long cost) {
  for (l += MAX, r += MAX + 1; l < r; l >>= 1, r >>= 1) {
    if (l & 1) add_edge(u, l, cost), l++;
    if (r & 1) r--, add_edge(u, r, cost);
  }
}
void add2(long long l, long long r, long long u, long long cost) {
  for (l += MAX, r += MAX + 1; l < r; l >>= 1, r >>= 1) {
    if (l & 1) add_edge(l + 2 * MAX, u, cost), l++;
    if (r & 1) r--, add_edge(r + 2 * MAX, u, cost);
  }
}
void make_dijkstra(long long s) {
  for (long long i = 1; i <= 10 * MAX - 1; i++) dp[i] = inf;
  dp[s] = 0;
  priority_queue<pair<long long, long long> > q;
  q.push(make_pair(0, s));
  while (!q.empty()) {
    pair<long long, long long> akt = q.top();
    q.pop();
    akt.first *= -1;
    if (akt.first != dp[akt.second]) continue;
    for (auto it : P[akt.second]) {
      if (dp[it.first] > akt.first + it.second) {
        dp[it.first] = akt.first + it.second;
        q.push(make_pair(-dp[it.first], it.first));
      }
    }
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, q, s;
  cin >> n >> q >> s;
  for (long long i = MAX + 1; i <= MAX * 2 - 1; i++)
    t1[i] = make_pair(i - MAX, i - MAX), t2[i] = make_pair(i - MAX, i - MAX),
    add_edge(i + 3 * MAX, i, 0), add_edge(i, i + 3 * MAX, 0),
    add_edge(i + 2 * MAX, i + 3 * MAX, 0),
    add_edge(i + 3 * MAX, i + 2 * MAX, 0);
  for (long long i = MAX - 1; i >= 1; i--) {
    t1[i] = make_pair(min(t1[2 * i].first, t1[2 * i + 1].first),
                      max(t1[2 * i].second, t1[2 * i + 1].second));
    for (long long j = t1[i].first; j <= t1[i].second; j++)
      add_edge(i, j + MAX, 0);
    t2[i] = make_pair(min(t2[2 * i].first, t2[2 * i + 1].first),
                      max(t2[2 * i].second, t2[2 * i + 1].second));
    for (long long j = t2[i].first; j <= t2[i].second; j++)
      add_edge(j + MAX * 3, i + MAX * 2, 0);
  }
  for (long long z = 1; z <= q; z++) {
    long long type;
    cin >> type;
    if (type == 1) {
      long long u, v, w;
      cin >> u >> v >> w;
      add_edge(u + 4 * MAX, v + 4 * MAX, w);
    } else if (type == 2) {
      long long u, l, r, w;
      cin >> u >> l >> r >> w;
      add1(l, r, u + MAX, w);
    } else if (type == 3) {
      long long u, l, r, w;
      cin >> u >> l >> r >> w;
      add2(l, r, u + MAX * 3, w);
    }
  }
  make_dijkstra(s + 4 * MAX);
  for (long long i = 4 * MAX + 1; i <= 4 * MAX + n; i++) {
    if (dp[i] == inf) dp[i] = -1;
    cout << dp[i] << " ";
  }
  return 0;
}
