#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
const int maxv = maxn * 5;
int n, m, s;
vector<pair<int, int>> G[maxv];
void addedge(int u, int v, int w) { G[u].push_back(make_pair(v, w)); }
int id[2][maxn << 2], idx;
void build(int l, int r, int rt) {
  id[0][rt] = ++idx;
  id[1][rt] = ++idx;
  if (l == r) {
    addedge(id[0][rt], l, 0);
    addedge(l, id[1][rt], 0);
    return;
  }
  int m = (l + r) / 2;
  build(l, m, rt * 2);
  build(m + 1, r, rt * 2 + 1);
  addedge(id[0][rt], id[0][rt * 2], 0);
  addedge(id[0][rt], id[0][rt * 2 + 1], 0);
  addedge(id[1][rt * 2], id[1][rt], 0);
  addedge(id[1][rt * 2 + 1], id[1][rt], 0);
}
vector<int> vs;
void get(int L, int R, int l, int r, int rt, int wh) {
  if (L <= l && r <= R) {
    vs.push_back(id[wh][rt]);
    return;
  }
  int m = (l + r) / 2;
  if (L <= m) get(L, R, l, m, rt * 2, wh);
  if (m < R) get(L, R, m + 1, r, rt * 2 + 1, wh);
}
const long long inf = 0x3f3f3f3f3f3f3f3fLL;
long long d[maxv];
bool vis[maxv];
void dij(int s) {
  for (int i = 1; i <= 5 * n; i++) vis[i] = 0, d[i] = inf;
  d[s] = 0;
  priority_queue<pair<long long, int>> q;
  q.push({-0, s});
  while (q.size()) {
    int u = q.top().second;
    q.pop();
    if (vis[u]) continue;
    vis[u] = 1;
    for (auto &e : G[u]) {
      int v, c;
      tie(v, c) = e;
      if (d[v] > d[u] + c) {
        d[v] = d[u] + c;
        q.push({-d[v], v});
      }
    }
  }
}
int main() {
  cin >> n >> m >> s;
  for (int i = 1; i <= 5 * n; i++) G[i].clear();
  idx = n;
  build(1, n, 1);
  while (m--) {
    int t, u;
    scanf("%d%d", &t, &u);
    if (t == 1) {
      int v, c;
      scanf("%d%d", &v, &c);
      addedge(u, v, c);
    } else if (t == 2) {
      vs.clear();
      int l, r, c;
      scanf("%d%d%d", &l, &r, &c);
      get(l, r, 1, n, 1, 0);
      for (int v : vs) addedge(u, v, c);
    } else {
      vs.clear();
      int l, r, c;
      scanf("%d%d%d", &l, &r, &c);
      get(l, r, 1, n, 1, 1);
      for (int v : vs) addedge(v, u, c);
    }
  }
  dij(s);
  for (int i = 1; i <= n; i++) {
    if (d[i] == inf) d[i] = -1;
    printf("%I64d ", d[i]);
  }
  printf("\n");
}
