#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long double pi = acos(-1);
const int MOD = 1e9 + 7;
const long long int LINF = 0x3f3f3f3f3f3f3f3f;
const int MAXN = 100005;
int n, q, s;
vector<pair<int, long long int> > graph[MAXN * 10];
long long int dist[MAXN * 10];
void edge(int u, int v, long long int c) { graph[u].push_back({v, c}); }
int mid(int b, int e) { return (b + e) / 2; }
void build(int nd, int b, int e) {
  if (b >= e) {
    edge(b, nd + n, 0);
    edge(nd + n, b, 0);
    edge(b, nd + MAXN * 6, 0);
    edge(nd + MAXN * 6, b, 0);
    return;
  }
  int l = 2 * nd;
  int r = 2 * nd + 1;
  edge(l + n, nd + n, 0);
  edge(r + n, nd + n, 0);
  edge(nd + MAXN * 6, l + MAXN * 6, 0);
  edge(nd + MAXN * 6, r + MAXN * 6, 0);
  build(l, b, mid(b, e));
  build(r, mid(b, e) + 1, e);
}
void update(int nd, int b, int e, int i, int j, int u, long long int c,
            bool rev) {
  if (i > e or j < b) return;
  if (b >= i and e <= j) {
    if (rev) {
      edge(nd + n, u, c);
    } else {
      edge(u, nd + MAXN * 6, c);
    }
    return;
  }
  update(2 * nd, b, mid(b, e), i, j, u, c, rev);
  update(2 * nd + 1, mid(b, e) + 1, e, i, j, u, c, rev);
}
void dijkstra() {
  dist[s] = 0;
  priority_queue<pair<long long int, long long int> > pq;
  pq.push({0, s});
  while (!pq.empty()) {
    int u = pq.top().second;
    long long int c = pq.top().first;
    c = -c;
    pq.pop();
    if (c > dist[u]) continue;
    for (pair<int, long long int> p : graph[u]) {
      int v = p.first;
      long long int nc = p.second;
      if (dist[v] > dist[u] + nc) {
        dist[v] = dist[u] + nc;
        pq.push({-dist[v], v});
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  ;
  cin >> n >> q >> s;
  build(1, 1, n);
  for (int i = 0; i < MAXN * 10; i++) dist[i] = LINF;
  for (int i = 0; i < q; i++) {
    int t;
    cin >> t;
    if (t == 1) {
      int u, v;
      long long int c;
      cin >> u >> v >> c;
      edge(u, v, c);
    } else if (t == 2) {
      int u, l, r;
      long long int c;
      cin >> u >> l >> r >> c;
      update(1, 1, n, l, r, u, c, 0);
    } else if (t == 3) {
      int u, l, r;
      long long int c;
      cin >> u >> l >> r >> c;
      update(1, 1, n, l, r, u, c, 1);
    }
  }
  dijkstra();
  for (int i = 1; i <= n; i++) {
    if (dist[i] >= LINF)
      cout << -1;
    else
      cout << dist[i];
    cout << " ";
  }
  cout << "\n";
  return 0;
}
