#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("O3")
#pragma GCC optimize("fast-math")
#pragma GCC optimize("Ofast")
using namespace std;
const int INF = 1e9;
const long long INFll = 2e18;
const int BASE1 = 179;
const int BASE2 = 653;
const long long MOD = 998244353;
const int MAXA = 2000001;
const int MAXN = 101;
const int MAXLOG = 22;
const long long COST = 1000 * 1000 * 1000;
const long double PI = 3.1415926535;
const long double EPS = 1e-15;
vector<vector<pair<long long, long long> > > g;
vector<int> numv;
int getrv(int v, int l, int r, int n) {
  if (l == r - 1) return v;
  return v + 4 * n;
}
void build(int v, int l, int r, int n) {
  if (l == r - 1) {
    numv[l] = v;
    return;
  }
  int mid = (l + r) / 2;
  build(2 * v + 1, l, mid, n);
  build(2 * v + 2, mid, r, n);
  g[v].emplace_back(make_pair(2 * v + 1, 0));
  g[v].emplace_back(make_pair(2 * v + 2, 0));
  g[getrv(2 * v + 1, l, mid, n)].emplace_back(make_pair(getrv(v, l, r, n), 0));
  g[getrv(2 * v + 2, mid, r, n)].emplace_back(make_pair(getrv(v, l, r, n), 0));
}
void init(long long n) {
  g.resize(8 * n);
  numv.resize(n);
  build(0, 0, n, n);
}
void add_v_v(int i, int j, long long cost) {
  g[numv[i]].emplace_back(make_pair(numv[j], cost));
}
void add_group_v(int v, int l, int r, int lq, int rq, int i, long long cost,
                 int n) {
  if (lq >= r || rq <= l) return;
  if (lq <= l && r <= rq) {
    int u = numv[i];
    g[getrv(v, l, r, n)].emplace_back(make_pair(u, cost));
    return;
  }
  int mid = (l + r) / 2;
  add_group_v(2 * v + 1, l, mid, lq, rq, i, cost, n);
  add_group_v(2 * v + 2, mid, r, lq, rq, i, cost, n);
}
void add_v_group(int v, int l, int r, int lq, int rq, int i, long long cost) {
  if (lq >= r || rq <= l) return;
  if (lq <= l && r <= rq) {
    int u = numv[i];
    g[u].emplace_back(make_pair(v, cost));
    return;
  }
  int mid = (l + r) / 2;
  add_v_group(2 * v + 1, l, mid, lq, rq, i, cost);
  add_v_group(2 * v + 2, mid, r, lq, rq, i, cost);
}
long long extract_min(set<pair<long long, long long> >& dist_set) {
  long long v = dist_set.begin()->second;
  dist_set.erase(dist_set.begin());
  return v;
}
void relax(long long v, set<pair<long long, long long> >& dist_set,
           vector<long long>& dist) {
  for (pair<long long, long long> e : g[v]) {
    if (dist[e.first] > dist[v] + e.second) {
      dist_set.erase(make_pair(dist[e.first], e.first));
      dist[e.first] = dist[v] + e.second;
      dist_set.insert(make_pair(dist[e.first], e.first));
    }
  }
}
void solve() {
  long long n, q, s;
  cin >> n >> q >> s;
  s--;
  init(n);
  for (int i = 0; i < (q); i++) {
    int t;
    cin >> t;
    if (t == 1) {
      long long u, v, cost;
      cin >> u >> v >> cost;
      u--;
      v--;
      add_v_v(u, v, cost);
    } else {
      long long v, l, r, cost;
      cin >> v >> l >> r >> cost;
      v--;
      l--;
      if (t == 2)
        add_v_group(0, 0, n, l, r, v, cost);
      else
        add_group_v(0, 0, n, l, r, v, cost, n);
    }
  }
  set<pair<long long, long long> > dist_set;
  vector<long long> dist(8 * n, INFll);
  dist[numv[s]] = 0;
  dist_set.insert(make_pair(0, numv[s]));
  while (!dist_set.empty()) {
    long long v = extract_min(dist_set);
    relax(v, dist_set, dist);
  }
  for (int i = 0; i < (n); i++) {
    if (dist[numv[i]] == INFll)
      cout << -1 << " ";
    else
      cout << dist[numv[i]] << " ";
  }
  cout << "\n";
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) solve();
  return 0;
}
