#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const int N = 100100;
template <int N>
class segmentTree {
  struct node {
    LL w, v[10];
    int l, r, a[10], lazy;
    node(int l = 0, int r = 0) : l(l), r(r), lazy(0) {
      for (int i = 0; i < 10; i++) a[i] = i;
      memset(v, 0, sizeof v);
    }
    void maintain() {
      w = 0;
      for (int i = 0; i < 10; i++) w += a[i] * v[i];
    }
    void update(int b[]) {
      for (int i = 0; i < 10; i++) a[i] = b[a[i]];
      lazy = 1;
    }
  } t[N * 4];
  void pushup(int x) {
    t[x].lazy = 0;
    memset(t[x].v, 0, sizeof t[x].v);
    for (int i = 0; i < 10; i++) {
      t[x].v[t[x << 1].a[i]] += t[x << 1].v[i];
      t[x].v[t[x << 1 | 1].a[i]] += t[x << 1 | 1].v[i];
      t[x].a[i] = i;
    }
  }
  void pushdown(int x) {
    if (t[x].lazy) {
      t[x << 1].update(t[x].a);
      t[x << 1 | 1].update(t[x].a);
      t[x].lazy = 0;
    }
  }

 public:
  void build(int x, int l, int r) {
    t[x] = node(l, r);
    if (l != r) {
      int md = l + r >> 1;
      build(x << 1, l, md);
      build(x << 1 | 1, md + 1, r);
    }
  }
  void add(int x, int l, int r, string s) {
    if (t[x].l >= l && t[x].r <= r) {
      for (int i = 0, k = 1; i < s.size(); i++, k *= 10) t[x].v[s[i] - 48] += k;
      t[x].maintain();
      return;
    }
    int md = t[x].l + t[x].r >> 1;
    if (md >= l) add(x << 1, l, r, s);
    if (md < r) add(x << 1 | 1, l, r, s);
    pushup(x);
    for (int i = 0; i < 10; i++)
      t[x].v[i] = t[x << 1].v[i] + t[x << 1 | 1].v[i];
  }
  void update(int x, int l, int r, int src, int des) {
    if (t[x].l >= l && t[x].r <= r) {
      for (int i = 0; i < 10; i++)
        if (t[x].a[i] == src) t[x].a[i] = des;
      t[x].lazy = 1;
      return;
    }
    pushdown(x);
    int md = t[x].l + t[x].r >> 1;
    if (md >= l) update(x << 1, l, r, src, des);
    if (md < r) update(x << 1 | 1, l, r, src, des);
    pushup(x);
  }
  LL sum(int x, int l, int r) {
    if (t[x].l >= l && t[x].r <= r) {
      t[x].maintain();
      return t[x].w;
    }
    pushdown(x);
    int md = t[x].l + t[x].r >> 1;
    LL res = 0;
    if (md >= l) res += sum(x << 1, l, r);
    if (md < r) res += sum(x << 1 | 1, l, r);
    pushup(x);
    return res;
  }
};
segmentTree<N> tree;
int main() {
  int n, q;
  scanf("%d %d", &n, &q);
  tree.build(1, 1, n);
  for (int i = 1; i <= n; i++) {
    string s;
    cin >> s;
    reverse(s.begin(), s.end());
    tree.add(1, i, i, s);
  }
  while (q--) {
    int t, l, r, x, y;
    scanf("%d %d %d", &t, &l, &r);
    if (t == 1) {
      scanf("%d %d", &x, &y);
      tree.update(1, l, r, x, y);
    } else {
      printf("%lld\n", tree.sum(1, l, r));
    }
  }
  return 0;
}
