#include <bits/stdc++.h>
using namespace std;
const int MAX = 100005;
const long long INF = 1000000000LL * 1000000;
int n, m, start;
int sz = 1, st1, st2;
vector<pair<int, int> > v[MAX + MAX << 3];
inline void Build(int k) {
  if (k >= sz) {
    v[st1 + k].push_back(pair<int, int>(k - sz + 1, 0));
    v[k - sz + 1].push_back(pair<int, int>(st2 + k, 0));
    return;
  }
  v[st1 + k].push_back(pair<int, int>(st1 + (k << 1), 0));
  v[st1 + k].push_back(pair<int, int>(st1 + (k << 1) + 1, 0));
  v[st2 + (k << 1)].push_back(pair<int, int>(st2 + k, 0));
  v[st2 + (k << 1) + 1].push_back(pair<int, int>(st2 + k, 0));
  Build(k << 1);
  Build((k << 1) + 1);
}
int type, x, y, l, r, w;
inline void Add(int k, int a, int b) {
  if (a > r || b < l) return;
  if (a >= l && b <= r) {
    if (type == 2)
      v[x].push_back(pair<int, int>(st1 + k, w));
    else
      v[st2 + k].push_back(pair<int, int>(x, w));
    return;
  }
  Add(k << 1, a, (a + b) >> 1);
  Add((k << 1) + 1, ((a + b) >> 1) + 1, b);
}
long long d[MAX + (MAX << 3)];
bool vis[MAX + (MAX << 3)];
priority_queue<pair<long long, int> > Q;
int main() {
  scanf("%d%d%d", &n, &m, &start);
  while (sz < n) sz <<= 1;
  st1 = n;
  st2 = n + (sz << 1) - 1;
  Build(1);
  while (m--) {
    scanf("%d", &type);
    if (type == 1) {
      scanf("%d%d%d", &x, &y, &w);
      v[x].push_back(pair<int, int>(y, w));
    } else {
      scanf("%d%d%d%d", &x, &l, &r, &w);
      Add(1, 1, sz);
    }
  }
  for (int i = 1; i < n + (sz << 2); i++) d[i] = INF;
  Q.push(make_pair(0, start));
  d[start] = 0;
  while (!Q.empty()) {
    int cur = Q.top().second;
    long long D = -Q.top().first;
    Q.pop();
    if (vis[cur]) continue;
    vis[cur] = true;
    for (int i = 0; i < v[cur].size(); i++) {
      int next = v[cur][i].first, weight = v[cur][i].second;
      if (D + weight < d[next]) {
        d[next] = D + weight;
        Q.push(make_pair(-d[next], next));
      }
    }
  }
  for (int i = 1; i <= n; i++) printf("%I64d ", d[i] == INF ? -1 : d[i]);
  return 0;
}
