#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
int lz[N << 2][10], n, q, op, l, r, x, y;
long long sum[N << 2][10], tr[10];
void Up(int K) {
  for (int i = 0; i < 10; ++i) sum[K][i] = 0;
  for (int i = 0; i < 10; ++i) sum[K][lz[(K << 1)][i]] += sum[(K << 1)][i];
  for (int i = 0; i < 10; ++i)
    sum[K][lz[(K << 1 | 1)][i]] += sum[(K << 1 | 1)][i];
}
void build(int K, int l, int r) {
  for (int i = 0; i < 10; ++i) lz[K][i] = i, sum[K][i] = 0;
  if (l == r) {
    int t, tr = 1;
    scanf("%d", &t);
    while (t) sum[K][t % 10] += tr, tr *= 10, t /= 10;
    return;
  }
  int m = (l + r) >> 1;
  build((K << 1), l, m);
  build((K << 1 | 1), m + 1, r);
  for (int i = 0; i < 10; ++i)
    sum[K][i] = sum[(K << 1)][i] + sum[(K << 1 | 1)][i];
  Up(K);
}
void Down(int K) {
  for (int i = 0; i < 10; ++i) lz[(K << 1)][i] = lz[K][lz[(K << 1)][i]];
  for (int i = 0; i < 10; ++i) lz[(K << 1 | 1)][i] = lz[K][lz[(K << 1 | 1)][i]];
  memset(tr, 0, sizeof(tr));
  for (int i = 0; i < 10; ++i) tr[lz[K][i]] += sum[K][i];
  for (int i = 0; i < 10; ++i) sum[K][i] = tr[i];
  for (int i = 0; i < 10; ++i) lz[K][i] = i;
}
void mdf(int K, int l, int r, int ql, int qr, int x, int y) {
  if (ql <= l && qr >= r) {
    for (int i = 0; i < 10; ++i)
      if (lz[K][i] == x) lz[K][i] = y;
    return;
  }
  Down(K);
  int m = (l + r) >> 1;
  if (ql <= m) mdf((K << 1), l, m, ql, qr, x, y);
  if (qr > m) mdf((K << 1 | 1), m + 1, r, ql, qr, x, y);
  Up(K);
}
long long Ask(int K, int l, int r, int ql, int qr) {
  long long re = 0;
  if (ql <= l && qr >= r) {
    for (int i = 0; i < 10; ++i) re += sum[K][i] * lz[K][i];
    return re;
  }
  Down(K);
  int m = (l + r) >> 1;
  if (ql <= m) re += Ask((K << 1), l, m, ql, qr);
  if (qr > m) re += Ask((K << 1 | 1), m + 1, r, ql, qr);
  return re;
}
int main() {
  scanf("%d%d", &n, &q);
  build(1, 1, n);
  while (q--) {
    scanf("%d%d%d", &op, &l, &r);
    if (op == 1) {
      scanf("%d%d", &x, &y);
      mdf(1, 1, n, l, r, x, y);
    } else
      printf("%lld\n", Ask(1, 1, n, l, r));
  }
  return 0;
}
