#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int n, q, s[maxn][10], h[maxn * 4][10];
long long w[maxn * 4][10], f[10];
inline int _read() {
  int num = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') ch = getchar();
  while (ch >= '0' && ch <= '9') num = num * 10 + ch - 48, ch = getchar();
  return num;
}
void up(int x) {
  memset(w[x], 0, sizeof(w[x]));
  for (int i = 0; i < 10; i++)
    w[x][h[(x << 1)][i]] += w[(x << 1)][i],
        w[x][h[((x << 1) + 1)][i]] += w[((x << 1) + 1)][i];
}
void Pushdown(int x) {
  for (int i = 0; i < 10; i++)
    h[(x << 1)][i] = h[x][h[(x << 1)][i]],
            h[((x << 1) + 1)][i] = h[x][h[((x << 1) + 1)][i]];
  memset(f, 0, sizeof(f));
  for (int i = 0; i < 10; i++) f[h[x][i]] += w[x][i];
  for (int i = 0; i < 10; i++) w[x][i] = f[i], h[x][i] = i;
}
void Build(int x, int L, int R) {
  for (int i = 0; i < 10; i++) h[x][i] = i;
  if (L == R) {
    for (int i = 0; i < 10; i++) w[x][i] = s[L][i];
    return;
  }
  int mid = L + (R - L >> 1);
  Build((x << 1), L, mid);
  Build(((x << 1) + 1), mid + 1, R);
  up(x);
}
long long ask(int x, int l, int r, int L, int R) {
  if (l < r) Pushdown(x);
  if (l == L && r == R) {
    long long num = 0;
    for (int i = 0; i < 10; i++) num += w[x][i] * h[x][i];
    return num;
  }
  int mid = l + (r - l >> 1);
  if (R <= mid)
    return ask((x << 1), l, mid, L, R);
  else if (L > mid)
    return ask(((x << 1) + 1), mid + 1, r, L, R);
  else
    return ask((x << 1), l, mid, L, mid) +
           ask(((x << 1) + 1), mid + 1, r, mid + 1, R);
}
void change(int x, int l, int r, int L, int R, int w, int y) {
  if (l < r) Pushdown(x);
  if (l == L && r == R) {
    for (int i = 0; i < 10; i++)
      if (h[x][i] == w) h[x][i] = y;
    return;
  }
  int mid = l + (r - l >> 1);
  if (R <= mid)
    change((x << 1), l, mid, L, R, w, y);
  else if (L > mid)
    change(((x << 1) + 1), mid + 1, r, L, R, w, y);
  else
    change((x << 1), l, mid, L, mid, w, y),
        change(((x << 1) + 1), mid + 1, r, mid + 1, R, w, y);
  up(x);
}
int main() {
  n = _read(), q = _read();
  for (int i = 1; i <= n; i++) {
    int x = _read(), now = 1;
    while (1) {
      s[i][x % 10] += now;
      now *= 10;
      x /= 10;
      if (!x) break;
    }
  }
  Build(1, 1, n);
  while (q--) {
    int h = _read(), L = _read(), R = _read(), x, y;
    if (h == 1)
      x = _read(), y = _read(), change(1, 1, n, L, R, x, y);
    else
      printf("%lld\n", ask(1, 1, n, L, R));
  }
  return 0;
}
