#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, q, p[N][10];
long long T[N << 2][10];
int lz[N << 2][10];
void push(int v, int l, int r) {
  if (l < r) {
    for (int i = 0; i < 10; ++i) {
      lz[v << 1][i] = lz[v][lz[v << 1][i]];
      lz[v << 1 | 1][i] = lz[v][lz[v << 1 | 1][i]];
    }
  }
  long long cur[10] = {};
  for (int i = 0; i < 10; ++i) cur[i] = 0;
  for (int i = 0; i < 10; ++i) cur[lz[v][i]] += T[v][i];
  for (int i = 0; i < 10; ++i) T[v][i] = cur[i], lz[v][i] = i;
}
void upd(int v, int l, int r, int L, int R, int x, int y) {
  push(v, l, r);
  if (l > r || R < l || L > r) return;
  if (L <= l && r <= R) {
    lz[v][x] = y;
    push(v, l, r);
    return;
  }
  upd(v << 1, l, ((l + r) >> 1), L, R, x, y);
  upd(v << 1 | 1, ((l + r) >> 1) + 1, r, L, R, x, y);
  for (int i = 0; i < 10; ++i) T[v][i] = T[v << 1][i] + T[v << 1 | 1][i];
}
long long get(int v, int l, int r, int L, int R) {
  push(v, l, r);
  if (l > r || R < l || L > r) return 0;
  if (L <= l && r <= R) {
    long long res = 0;
    for (int i = 0; i < 10; ++i) res += T[v][i] * i;
    return res;
  }
  return get(v << 1, l, ((l + r) >> 1), L, R) +
         get(v << 1 | 1, ((l + r) >> 1) + 1, r, L, R);
}
void build(int v, int l, int r) {
  if (l == r) {
    for (int i = 0; i < 10; ++i) T[v][i] = p[l][i], lz[v][i] = i;
    return;
  }
  build(v << 1, l, ((l + r) >> 1));
  build(v << 1 | 1, ((l + r) >> 1) + 1, r);
  for (int i = 0; i < 10; ++i)
    T[v][i] = T[v << 1][i] + T[v << 1 | 1][i], lz[v][i] = i;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> q;
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    int pw = 1;
    while (x) {
      p[i][x % 10] += pw;
      pw *= 10;
      x /= 10;
    }
  }
  build(1, 1, n);
  while (q--) {
    int tp;
    cin >> tp;
    if (tp == 1) {
      int l, r, x, y;
      cin >> l >> r >> x >> y;
      upd(1, 1, n, l, r, x, y);
    } else {
      int l, r;
      cin >> l >> r;
      printf("%lld\n", get(1, 1, n, l, r));
    }
  }
}
