#include <bits/stdc++.h>
using namespace std;
const int N = int(5e5) + 5;
const int inf = (int)1e9 + 7;
int B = 175;
vector<int> tmpe(10, 0);
struct block {
  int nxt[10], sz;
  long long cur[10], sum;
  int e[176][10];
  block() {
    for (int d = 0; d <= 9; ++d) {
      nxt[d] = d;
    }
  }
  void refresh() {
    for (int i = 0; i < sz; ++i) {
      for (int d = 0; d <= 9; ++d) {
        tmpe[d] = 0;
      }
      for (int d = 0; d <= 9; ++d) {
        tmpe[nxt[d]] += e[i][d];
      }
      for (int d = 0; d <= 9; ++d) {
        e[i][d] = tmpe[d];
      }
    }
    for (int d = 0; d <= 9; ++d) {
      nxt[d] = d;
    }
  }
};
int n, q;
int id[N], ps[N];
block st[701];
void upd(int l, int r, int x, int y) {
  --l, --r;
  if (id[l] == id[r]) {
    st[id[l]].refresh();
    for (int j = ps[l]; j <= ps[r]; ++j) {
      st[id[l]].cur[y] += st[id[l]].e[j][x];
      st[id[l]].sum -= st[id[l]].e[j][x] * 1ll * x;
      st[id[l]].e[j][y] += st[id[l]].e[j][x];
      st[id[l]].sum += st[id[l]].e[j][x] * 1ll * y;
      st[id[l]].cur[x] -= st[id[l]].e[j][x];
      st[id[l]].e[j][x] = 0;
    }
  } else {
    st[id[l]].refresh();
    for (int j = ps[l]; j < st[id[l]].sz; ++j) {
      st[id[l]].cur[y] += st[id[l]].e[j][x];
      st[id[l]].sum -= st[id[l]].e[j][x] * 1ll * x;
      st[id[l]].e[j][y] += st[id[l]].e[j][x];
      st[id[l]].sum += st[id[l]].e[j][x] * 1ll * y;
      st[id[l]].cur[x] -= st[id[l]].e[j][x];
      st[id[l]].e[j][x] = 0;
    }
    st[id[r]].refresh();
    for (int j = ps[r]; j >= 0; --j) {
      st[id[r]].cur[y] += st[id[r]].e[j][x];
      st[id[r]].sum -= st[id[r]].e[j][x] * 1ll * x;
      st[id[r]].e[j][y] += st[id[r]].e[j][x];
      st[id[r]].sum += st[id[r]].e[j][x] * 1ll * y;
      st[id[r]].cur[x] -= st[id[r]].e[j][x];
      st[id[r]].e[j][x] = 0;
    }
    for (int j = id[l] + 1; j < id[r]; ++j) {
      for (int d = 0; d <= 9; ++d) {
        if (st[j].nxt[d] == x) {
          st[j].nxt[d] = y;
        }
      }
      st[j].sum -= st[j].cur[x] * x;
      st[j].sum += st[j].cur[x] * y;
      st[j].cur[y] += st[j].cur[x];
      st[j].cur[x] = 0;
    }
  }
}
long long get(int l, int r) {
  --l, --r;
  long long ans = 0;
  if (id[l] == id[r]) {
    st[id[l]].refresh();
    for (int j = ps[l]; j <= ps[r]; ++j) {
      for (int d = 1; d <= 9; ++d) {
        ans += st[id[l]].e[j][d] * 1ll * d;
      }
    }
  } else {
    st[id[l]].refresh();
    for (int j = ps[l]; j < st[id[l]].sz; ++j) {
      for (int d = 1; d <= 9; ++d) {
        ans += st[id[l]].e[j][d] * 1ll * d;
      }
    }
    st[id[r]].refresh();
    for (int j = ps[r]; j >= 0; --j) {
      for (int d = 1; d <= 9; ++d) {
        ans += st[id[r]].e[j][d] * 1ll * d;
      }
    }
    for (int j = id[l] + 1; j < id[r]; ++j) {
      ans += st[j].sum;
    }
  }
  return ans;
}
int main() {
  scanf("%d %d", &n, &q);
  for (int i = 1; i <= n; ++i) {
    int x;
    scanf("%d", &x);
    vector<int> tmp(10, 0);
    long long te = 1;
    id[i - 1] = (i - 1) / B;
    ps[i - 1] = (i - 1) - id[i - 1] * B;
    while (x) {
      tmp[x % 10] += te;
      st[id[i - 1]].cur[x % 10] += te;
      te *= 10;
      x /= 10;
    }
    for (int d = 0; d <= 9; ++d) {
      st[id[i - 1]].sum += tmp[d] * d;
    }
    for (int d = 0; d <= 9; ++d) {
      st[id[i - 1]].e[st[id[i - 1]].sz][d] = tmp[d];
    }
    st[id[i - 1]].sz++;
  }
  for (int i = 1; i <= q; ++i) {
    int t, l, r;
    scanf("%d %d %d", &t, &l, &r);
    if (t == 1) {
      int x, y;
      scanf("%d %d", &x, &y);
      if (x == y) {
        continue;
      }
      upd(l, r, x, y);
    } else {
      printf("%lld\n", get(l, r));
    }
  }
  return 0;
}
