#include <bits/stdc++.h>
using namespace std;
int mult(int x, int y) {
  long long int ans, x1 = (long long int)x, y1 = (long long int)y;
  ans = (x1 * y1) % 1000000007;
  return (int)ans;
}
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int lcm(int a, int b) { return a * (b / gcd(a, b)); }
long long int pow1(long long int a, long long int b) {
  long long int ans = 1;
  while (b > 0) {
    if (b & 1) ans = (ans * a) % 1000000007;
    a = (a * a) % 1000000007;
    b >>= 1;
  }
  return ans;
}
vector<vector<pair<int, long long int> > > v;
long long int dist[1000005];
int n;
int in[400005], out[400005], curr;
void build(int low, int high, int pos) {
  if (low == high) {
    in[pos] = out[pos] = low;
    return;
  } else {
    in[pos] = ++curr;
    out[pos] = ++curr;
  }
  int mid = (low + high) >> 1;
  build(low, mid, 2 * pos);
  build(mid + 1, high, 2 * pos + 1);
  v[out[pos]].push_back(make_pair(out[2 * pos], 0));
  v[out[pos]].push_back(make_pair(out[2 * pos + 1], 0));
  v[in[2 * pos]].push_back(make_pair(in[pos], 0));
  v[in[2 * pos + 1]].push_back(make_pair(in[pos], 0));
}
void query1(int low, int high, int pos, int l, int r, int x, int w) {
  if (low > r || high < l) return;
  if (low >= l && high <= r) {
    v[x].push_back(make_pair(out[pos], w));
    return;
  }
  int mid = (low + high) >> 1;
  query1(low, mid, 2 * pos, l, r, x, w);
  query1(mid + 1, high, 2 * pos + 1, l, r, x, w);
}
void query2(int low, int high, int pos, int l, int r, int x, int w) {
  if (low > r || high < l) return;
  if (low >= l && high <= r) {
    v[in[pos]].push_back(make_pair(x, w));
    return;
  }
  int mid = (low + high) >> 1;
  query2(low, mid, 2 * pos, l, r, x, w);
  query2(mid + 1, high, 2 * pos + 1, l, r, x, w);
}
priority_queue<pair<long long int, int> > pq;
void dijkstra(int src) {
  int i;
  pq.push(make_pair(0, src));
  dist[src] = 0;
  pair<long long int, int> front;
  long long int d, ver;
  while (!pq.empty()) {
    front = pq.top();
    pq.pop();
    d = -front.first;
    ver = front.second;
    if (d > dist[ver]) continue;
    for (i = 0; i < v[ver].size(); i++) {
      int v1 = v[ver][i].first;
      long long int w = v[ver][i].second;
      if (dist[ver] + w < dist[v1]) {
        dist[v1] = dist[ver] + w;
        pq.push(make_pair(-dist[v1], v1));
      }
    }
  }
}
int main() {
  int q, i, j, s, x, y, l, r, w;
  scanf("%d", &n);
  scanf("%d", &q);
  scanf("%d", &s);
  v.resize(10 * n + 2);
  curr = n;
  build(1, n, 1);
  while (q--) {
    int ch;
    scanf("%d", &ch);
    if (ch == 1) {
      scanf("%d", &x);
      scanf("%d", &y);
      scanf("%d", &w);
      v[x].push_back((make_pair(y, w)));
    } else if (ch == 2) {
      scanf("%d", &x);
      scanf("%d", &l);
      scanf("%d", &r);
      scanf("%d", &w);
      query1(1, n, 1, l, r, x, w);
    } else {
      scanf("%d", &x);
      scanf("%d", &l);
      scanf("%d", &r);
      scanf("%d", &w);
      query2(1, n, 1, l, r, x, w);
    }
  }
  for (i = 1; i < 5 * n + 2; i++) dist[i] = 1e15;
  dijkstra(s);
  for (i = 1; i < n + 1; i++) {
    if (dist[i] == 1e15)
      printf("-1 ");
    else
      printf("%lld ", dist[i]);
  }
  printf("\n");
  return 0;
}
