#include <bits/stdc++.h>
using namespace std;
long long n, q, a[500005], it[500005][15], lazy[500005][15];
long long power[20];
void build_tree(long long k, long long l, long long r, long long d) {
  if (l == r) {
    long long idem = 1;
    while (a[l] > 0) {
      it[k][a[l] % 10] += idem;
      idem *= 10;
      a[l] /= 10;
    }
    lazy[k][d] = d;
    return;
  }
  long long mid = (l + r) / 2;
  build_tree(k * 2, l, mid, d);
  build_tree(k * 2 + 1, mid + 1, r, d);
  it[k][d] = it[k * 2][d] + it[k * 2 + 1][d];
  lazy[k][d] = d;
}
void lazyupdate(long long k, long long l, long long r) {
  long long rem[15];
  memset(rem, 0, sizeof(rem));
  for (int i = 0; i <= 9; i++) {
    rem[lazy[k][i]] += it[k][i];
    it[k][i] = 0;
  }
  if (l != r) {
    for (int i = 0; i <= 9; i++) {
      lazy[k * 2][i] = lazy[k][lazy[k * 2][i]];
      lazy[k * 2 + 1][i] = lazy[k][lazy[k * 2 + 1][i]];
    }
  }
  for (int i = 0; i <= 9; i++) {
    it[k][i] = rem[i];
    lazy[k][i] = i;
  }
}
void update(long long k, long long l, long long r, long long L, long long R,
            long long x, long long y) {
  lazyupdate(k, l, r);
  if (R < l || r < L || L > R) return;
  if (L <= l && r <= R) {
    it[k][y] += it[k][x];
    it[k][x] = 0;
    if (l != r) {
      for (int i = 0; i <= 9; i++) {
        if (lazy[k * 2][i] == x) lazy[k * 2][i] = y;
        if (lazy[k * 2 + 1][i] == x) lazy[k * 2 + 1][i] = y;
      }
    }
    return;
  }
  long long mid = (l + r) / 2;
  update(k * 2, l, mid, L, R, x, y);
  update(k * 2 + 1, mid + 1, r, L, R, x, y);
  for (long long i = 0; i <= 9; i++) it[k][i] = it[k * 2][i] + it[k * 2 + 1][i];
}
long long get(long long k, long long l, long long r, long long L, long long R) {
  lazyupdate(k, l, r);
  if (R < l || r < L || L > R) return 0LL;
  if (L <= l && r <= R) {
    long long num = 0LL;
    for (long long i = 1; i <= 9; i++) num += it[k][i] * i;
    return num;
  }
  long long mid = (l + r) / 2;
  return get(k * 2, l, mid, L, R) + get(k * 2 + 1, mid + 1, r, L, R);
  for (long long i = 0; i <= 9; i++) it[k][i] = it[k * 2][i] + it[k * 2 + 1][i];
}
int main() {
  cin.tie(0), cout.tie(0), ios::sync_with_stdio(0);
  cin >> n >> q;
  power[0] = 1;
  for (long long i = 1; i <= 18; i++) power[i] = power[i - 1] * 10LL;
  for (long long i = 1; i <= n; i++) cin >> a[i];
  for (long long i = 0; i <= 9; i++) build_tree(1, 1, n, i);
  long long l, r, type, x, y;
  while (q--) {
    cin >> type >> l >> r;
    if (type == 1) {
      cin >> x >> y;
      if (x != y) update(1, 1, n, l, r, x, y);
    } else
      cout << get(1, 1, n, l, r) << "\n";
  }
}
