#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> G[10 * 100005];
priority_queue<pair<long long, int>, vector<pair<long long, int>>,
               greater<pair<long long, int>>>
    q;
int n, root1, root2, u, v, w, l, r, op, Q, s, cnt, node[100005];
bool done[10 * 100005];
long long d[10 * 100005];
struct Tree {
  int l, r, ls, rs;
} tr[8 * 100005];
void Build(int &u, int l, int r, int op) {
  u = ++cnt;
  tr[u].l = l;
  tr[u].r = r;
  if (l == r) {
    if (op == 0)
      G[u].push_back(make_pair(node[l], 0));
    else
      G[node[l]].push_back(make_pair(u, 0));
    return;
  }
  int mid = (l + r) >> 1;
  Build(tr[u].ls, l, mid, op);
  Build(tr[u].rs, mid + 1, r, op);
  if (op == 0) {
    G[u].push_back(make_pair(tr[u].ls, 0));
    G[u].push_back(make_pair(tr[u].rs, 0));
  } else {
    G[tr[u].ls].push_back(make_pair(u, 0));
    G[tr[u].rs].push_back(make_pair(u, 0));
  }
}
void Add(int u, int v, int x, int y, int w, int op) {
  int l = tr[u].l, r = tr[u].r;
  if (l == x && r == y) {
    if (op == 2)
      G[v].push_back(make_pair(u, w));
    else
      G[u].push_back(make_pair(v, w));
    return;
  }
  int mid = (l + r) >> 1;
  if (y <= mid)
    Add(tr[u].ls, v, x, y, w, op);
  else if (x <= mid) {
    Add(tr[u].ls, v, x, mid, w, op);
    Add(tr[u].rs, v, mid + 1, y, w, op);
  } else
    Add(tr[u].rs, v, x, y, w, op);
}
int main() {
  scanf("%d%d%d", &n, &Q, &s);
  for (int i = 1; i <= n; i++) node[i] = 8 * n + i;
  Build(root1, 1, n, 0);
  Build(root2, 1, n, 1);
  for (int i = 1; i <= Q; i++) {
    scanf("%d", &op);
    if (op == 1) {
      scanf("%d%d%d", &u, &v, &w);
      G[node[u]].push_back(make_pair(node[v], w));
    } else {
      scanf("%d%d%d%d", &u, &l, &r, &w);
      Add((op == 2) ? root1 : root2, node[u], l, r, w, op);
    }
  }
  for (int i = 1; i <= 9 * n; i++)
    d[i] = (i == node[s]) ? 0ll : 100000000000000ll;
  memset(done, 0, sizeof(done));
  q.push(make_pair(d[node[s]], node[s]));
  while (!q.empty()) {
    int u = q.top().second;
    q.pop();
    if (done[u]) continue;
    done[u] = true;
    for (pair<int, int> v : G[u]) {
      if (d[v.first] > d[u] + v.second) {
        d[v.first] = d[u] + v.second;
        q.push(make_pair(d[v.first], v.first));
      }
    }
  }
  for (int i = 1; i <= n; i++)
    cout << (d[node[i]] == 100000000000000ll ? -1 : d[node[i]]) << " ";
}
