#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10, mod = 1e9 + 7;
int seg[4 * N][9][10], flag[4 * N][10], pw[9];
inline void relax(int ind) {
  int a[10];
  for (int i = 0; i < 9; i++) {
    for (int j = 0; j < 10; j++) a[j] = 0;
    for (int j = 0; j < 10; j++) a[flag[ind][j]] += seg[2 * ind][i][j];
    for (int j = 0; j < 10; j++) seg[2 * ind][i][j] = a[j];
    for (int j = 0; j < 10; j++) a[j] = 0;
    for (int j = 0; j < 10; j++) a[flag[ind][j]] += seg[2 * ind + 1][i][j];
    for (int j = 0; j < 10; j++) seg[2 * ind + 1][i][j] = a[j];
  }
  for (int i = 0; i < 10; i++) {
    flag[2 * ind][i] = flag[ind][flag[2 * ind][i]];
    flag[2 * ind + 1][i] = flag[ind][flag[2 * ind + 1][i]];
  }
  for (int i = 0; i < 10; i++) flag[ind][i] = i;
}
void build(int s, int e, int ind, int l, int r, int val) {
  if (s >= r || e <= l) return;
  if (s >= l && e <= r) {
    int cnt = 0;
    while (val) {
      seg[ind][cnt][val % 10]++;
      val /= 10;
      cnt++;
    }
    return;
  }
  int mid = (s + e) / 2;
  build(s, mid, 2 * ind, l, r, val);
  build(mid, e, 2 * ind + 1, l, r, val);
  for (int i = 0; i < 9; i++)
    for (int j = 0; j < 10; j++)
      seg[ind][i][j] = seg[2 * ind][i][j] + seg[2 * ind + 1][i][j];
}
void change(int s, int e, int ind, int l, int r, int x, int y) {
  if (s >= r || e <= l) return;
  if (s >= l && e <= r) {
    for (int j = 0; j < 10; j++)
      if (flag[ind][j] == x) flag[ind][j] = y;
    for (int i = 0; i < 9; i++) {
      if (y == x) continue;
      seg[ind][i][y] += seg[ind][i][x];
      seg[ind][i][x] = 0;
    }
    return;
  }
  relax(ind);
  int mid = (s + e) / 2;
  change(s, mid, 2 * ind, l, r, x, y);
  change(mid, e, 2 * ind + 1, l, r, x, y);
  for (int i = 0; i < 9; i++)
    for (int j = 0; j < 10; j++)
      seg[ind][i][j] = seg[2 * ind][i][j] + seg[2 * ind + 1][i][j];
}
long long get(int s, int e, int ind, int l, int r) {
  if (s >= r || e <= l) return 0ll;
  if (s >= l && e <= r) {
    long long ret = 0;
    for (int i = 0; i < 9; i++)
      for (int j = 1; j < 10; j++) ret += 1ll * pw[i] * j * seg[ind][i][j];
    return ret;
  }
  relax(ind);
  int mid = (s + e) / 2;
  return get(s, mid, 2 * ind, l, r) + get(mid, e, 2 * ind + 1, l, r);
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  pw[0] = 1;
  for (int i = 1; i < 9; i++) pw[i] = pw[i - 1] * 10;
  for (int i = 0; i < 4 * N; i++)
    for (int k = 0; k < 10; k++) flag[i][k] = k;
  int n, q;
  cin >> n >> q;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    build(0, n, 1, i, i + 1, x);
  }
  while (q--) {
    int tp, l, r;
    cin >> tp >> l >> r;
    l--;
    if (tp == 1) {
      int x, y;
      cin >> x >> y;
      change(0, n, 1, l, r, x, y);
    } else
      cout << get(0, n, 1, l, r) << "\n";
  }
  return 0;
}
