#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e6;
const long long INF = 1LL << 60;
struct NODE {
  int v, w;
  NODE(int vv, int ww) {
    v = vv;
    w = ww;
  }
};
vector<NODE> G[MAX];
long long dis[MAX];
bool vis[MAX];
int n;
void SPFA(int v0) {
  memset(vis, false, sizeof(vis));
  for (int i = 1; i <= 9 * n; i++) dis[i] = INF;
  dis[v0] = 0;
  queue<int> q;
  q.push(v0);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    vis[u] = false;
    int sz = G[u].size();
    for (int i = 0; i < sz; i++) {
      int v = G[u][i].v;
      int w = G[u][i].w;
      if (dis[v] > dis[u] + w) {
        dis[v] = dis[u] + w;
        if (!vis[v]) {
          q.push(v);
          vis[v] = true;
        }
      }
    }
  }
}
void build2(int o, int l, int r) {
  int lc = o * 2, rc = o * 2 + 1;
  if (l == r) {
    G[o + n].push_back(NODE(l, 0));
  } else {
    int m = (l + r) / 2;
    G[o + n].push_back(NODE(lc + n, 0));
    G[o + n].push_back(NODE(rc + n, 0));
    build2(lc, l, m);
    build2(rc, m + 1, r);
  }
}
void build3(int o, int l, int r) {
  int lc = o * 2, rc = o * 2 + 1;
  if (l == r) {
    G[l].push_back(NODE(5 * n + o, 0));
  } else {
    int m = (l + r) / 2;
    G[lc + 5 * n].push_back(NODE(o + 5 * n, 0));
    G[rc + 5 * n].push_back(NODE(o + 5 * n, 0));
    build3(lc, l, m);
    build3(rc, m + 1, r);
  }
}
void update2(int o, int l, int r, int x, int yl, int yr, int w) {
  int lc = o * 2, rc = o * 2 + 1;
  if (yl <= l && r <= yr) {
    G[x].push_back(NODE(o + n, w));
  } else {
    int m = (l + r) / 2;
    if (yl <= m) update2(lc, l, m, x, yl, yr, w);
    if (yr > m) update2(rc, m + 1, r, x, yl, yr, w);
  }
}
void update3(int o, int l, int r, int x, int yl, int yr, int w) {
  int lc = o * 2, rc = o * 2 + 1;
  if (yl <= l && r <= yr) {
    G[o + 5 * n].push_back(NODE(x, w));
  } else {
    int m = (l + r) / 2;
    if (yl <= m) update3(lc, l, m, x, yl, yr, w);
    if (yr > m) update3(rc, m + 1, r, x, yl, yr, w);
  }
}
int main() {
  int q, s;
  scanf("%d%d%d", &n, &q, &s);
  build2(1, 1, n);
  build3(1, 1, n);
  while (q--) {
    int k;
    scanf("%d", &k);
    if (k == 1) {
      int u, v, w;
      scanf("%d%d%d", &u, &v, &w);
      G[u].push_back(NODE(v, w));
    } else if (k == 2) {
      int v, l, r, w;
      scanf("%d%d%d%d", &v, &l, &r, &w);
      update2(1, 1, n, v, l, r, w);
    } else if (k == 3) {
      int v, l, r, w;
      scanf("%d%d%d%d", &v, &l, &r, &w);
      update3(1, 1, n, v, l, r, w);
    }
  }
  SPFA(s);
  for (int i = 1; i < n; i++) {
    if (dis[i] != INF)
      printf("%lld ", dis[i]);
    else
      printf("-1 ");
  }
  if (dis[n] != INF)
    printf("%lld ", dis[n]);
  else
    printf("-1\n");
}
