#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e5 + 10;
long long n, q, t, l, r, x, y, ret, a[MAXN], lazy[4 * MAXN][10],
    s[4 * MAXN][10];
inline void Build(long long id = 1, long long l = 0, long long r = n) {
  for (long long i = 0; i < 10; i++) lazy[id][i] = i;
  if (r - l == 1) {
    long long Power = 1, Num = a[l];
    while (Num) s[id][Num % 10] += Power, Num /= 10, Power *= 10;
    return;
  }
  Build((id << 1), l, ((l + r) >> 1)), Build((id << 1) + 1, ((l + r) >> 1), r);
  for (long long i = 0; i < 10; i++)
    s[id][i] = s[(id << 1)][i] + s[(id << 1) + 1][i];
}
inline void Update(long long id, long long Child) {
  long long SumTmp[10];
  for (long long i = 0; i < 10; i++) SumTmp[i] = 0;
  for (long long i = 0; i < 10; i++) {
    lazy[Child][i] = lazy[id][lazy[Child][i]];
    SumTmp[lazy[id][i]] += s[Child][i];
  }
  for (long long i = 0; i < 10; i++) s[Child][i] = SumTmp[i];
}
inline void Shift(long long id) {
  Update(id, (id << 1));
  Update(id, (id << 1) + 1);
  for (long long i = 0; i < 10; i++) lazy[id][i] = i;
}
inline void Set(long long le, long long ri, long long x, long long y,
                long long id = 1, long long l = 0, long long r = n) {
  if (r <= le or ri <= l) return;
  if (le <= l and r <= ri) {
    s[id][y] += s[id][x];
    s[id][x] = 0;
    for (long long i = 0; i < 10; i++)
      if (lazy[id][i] == x) lazy[id][i] = y;
    return;
  }
  Shift(id);
  Set(le, ri, x, y, (id << 1), l, ((l + r) >> 1)),
      Set(le, ri, x, y, (id << 1) + 1, ((l + r) >> 1), r);
  for (long long i = 0; i < 10; i++)
    s[id][i] = s[(id << 1)][i] + s[(id << 1) + 1][i];
}
inline void Get(long long le, long long ri, long long id = 1, long long l = 0,
                long long r = n) {
  if (r <= le or ri <= l) return;
  if (le <= l and r <= ri) {
    for (long long i = 0; i < 10; i++) ret += s[id][i] * i;
    return;
  }
  Shift(id);
  Get(le, ri, (id << 1), l, ((l + r) >> 1)),
      Get(le, ri, (id << 1) + 1, ((l + r) >> 1), r);
}
int32_t main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> q;
  for (long long i = 0; i < n; i++) cin >> a[i];
  Build();
  while (q--) {
    cin >> t >> l >> r, l--;
    if (t == 1) {
      cin >> x >> y;
      if (x != y) Set(l, r, x, y);
      continue;
    }
    ret = 0;
    Get(l, r);
    cout << ret << '\n';
  }
}
