#include <bits/stdc++.h>
using namespace std;
long long dp[4 * 100005];
vector<pair<int, int> > g[4 * 100005];
int n1[4 * 100005], n2[4 * 100005];
int num[100005];
int tot = 1;
void build(int n, int s, int e) {
  if (s == e) {
    num[s] = tot;
    n1[n] = n2[n] = tot++;
    return;
  } else {
    int mid = (s + e) / 2;
    build(n * 2, s, mid);
    build(n * 2 + 1, mid + 1, e);
    n1[n] = tot++;
    n2[n] = tot++;
    g[n1[n]].push_back(pair<int, int>(n1[n * 2], 0));
    g[n1[n]].push_back(pair<int, int>(n1[n * 2 + 1], 0));
    g[n2[n * 2]].push_back(pair<int, int>(n2[n], 0));
    g[n2[n * 2 + 1]].push_back(pair<int, int>(n2[n], 0));
  }
}
vector<int> node;
void getnode(int n, int s, int e, int l, int r) {
  if (s > r || l > e) return;
  if (l <= s && e <= r) {
    node.push_back(n);
    return;
  }
  int mid = (s + e) / 2;
  getnode(n * 2, s, mid, l, r);
  getnode(n * 2 + 1, mid + 1, e, l, r);
}
int n, q, s;
int main() {
  memset(dp, -1, sizeof(dp));
  scanf("%d%d%d", &n, &q, &s);
  build(1, 1, n);
  bool ok = 0;
  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);
      g[num[v]].push_back(pair<int, int>(num[u], w));
    } else if (t == 2) {
      int v, l, r, w;
      scanf("%d%d%d%d", &v, &l, &r, &w);
      node.clear();
      getnode(1, 1, n, l, r);
      for (int j = 0; j < node.size(); j++) {
        int u = node[j];
        g[num[v]].push_back(pair<int, int>(n1[u], w));
        g[num[v]].push_back(pair<int, int>(n2[u], w));
      }
    } else {
      int v, l, r, w;
      scanf("%d%d%d%d", &v, &l, &r, &w);
      node.clear();
      getnode(1, 1, n, l, r);
      for (int j = 0; j < node.size(); j++) {
        int u = node[j];
        g[n1[u]].push_back(pair<int, int>(num[v], w));
        g[n2[u]].push_back(pair<int, int>(num[v], w));
      }
    }
  }
  dp[num[s]] = 0;
  priority_queue<pair<long long, int> > pq;
  pq.push(pair<long long, int>(-dp[num[s]], num[s]));
  while (!pq.empty()) {
    int u = pq.top().second;
    long long val = -pq.top().first;
    pq.pop();
    if (val != dp[u]) continue;
    for (int i = 0; i < g[u].size(); i++) {
      int v = g[u][i].first, w = g[u][i].second;
      if (dp[v] == -1 || dp[v] > dp[u] + w) {
        dp[v] = dp[u] + w;
        pq.push(pair<long long, int>(-dp[v], v));
      }
    }
  }
  for (int i = 1; i <= n; i++) printf("%lld ", dp[num[i]]);
}
