#include <bits/stdc++.h>
const int MAXN = 100000 + 10;
const long long INF = 10000000000000000ll;
struct Seg {
  int ls, rs;
} tree[3 * MAXN];
struct Edge {
  int to, dis;
  Edge(int _a = 0, int _b = 0) {
    to = _a;
    dis = _b;
  }
};
struct pii {
  int first;
  long long second;
  pii(int _a = 0, long long _b = 0) {
    first = _a;
    second = _b;
  }
  bool operator<(const pii& rhs) const { return second > rhs.second; }
};
std::vector<Edge> G[3 * MAXN];
int n, q, s, tot, vis[3 * MAXN], root2;
long long d[3 * MAXN];
void Add(int u, int v, int d) { G[u].push_back(Edge(v, d)); }
void build(int x, int l, int r, int k) {
  if (l != r) {
    int mid = l + r >> 1;
    tree[x].ls = l == mid ? l : ++tot;
    build(tree[x].ls, l, mid, k);
    if (k)
      Add(tree[x].ls, x, 0);
    else
      Add(x, tree[x].ls, 0);
    tree[x].rs = mid + 1 == r ? r : ++tot;
    build(tree[x].rs, mid + 1, r, k);
    if (k)
      Add(tree[x].rs, x, 0);
    else
      Add(x, tree[x].rs, 0);
  }
}
void Insert(int x, int l, int r, int ql, int qr, int v, int k, int w) {
  if (ql <= l && qr >= r) {
    if (k)
      Add(v, x, w);
    else
      Add(x, v, w);
    return;
  }
  int mid = l + r >> 1;
  if (ql <= mid) Insert(tree[x].ls, l, mid, ql, qr, v, k, w);
  if (qr > mid) Insert(tree[x].rs, mid + 1, r, ql, qr, v, k, w);
}
void Dij() {
  std::priority_queue<pii> Q;
  for (int i = 1; i <= tot; ++i) {
    d[i] = INF;
  }
  d[s] = 0;
  Q.push(pii(s, 0));
  while (!Q.empty()) {
    int x = Q.top().first;
    Q.pop();
    if (vis[x]) continue;
    vis[x] = 1;
    for (int i = 0; i < G[x].size(); ++i) {
      int t = G[x][i].to;
      if (d[t] > G[x][i].dis + d[x]) {
        d[t] = G[x][i].dis + d[x];
        Q.push(pii(t, d[t]));
      }
    }
  }
}
int main() {
  scanf("%d%d%d", &n, &q, &s);
  tot = n + 1;
  build(n + 1, 1, n, 0);
  build(root2 = ++tot, 1, n, 1);
  for (int i = 1; i <= q; ++i) {
    int t;
    scanf("%d", &t);
    if (t == 1) {
      int v, u, w;
      scanf("%d%d%d", &v, &u, &w);
      Insert(root2, 1, n, v, v, u, 0, w);
    } else {
      int v, l, r, w;
      scanf("%d%d%d%d", &v, &l, &r, &w);
      if (t == 2) Insert(n + 1, 1, n, l, r, v, 1, w);
      if (t == 3) Insert(root2, 1, n, l, r, v, 0, w);
    }
  }
  Dij();
  for (int i = 1; i <= n; ++i) {
    printf("%I64d ", d[i] == INF ? -1 : d[i]);
  }
  return 0;
}
