/*************************************************************************
  >         File: E.cc
  >       Author: Yuan Lei
  >         Mail: yuanlei@indeed.com
  > Created Time: Sat May 13 19:42:08 2017
*************************************************************************/
#include <vector>
#include <cstdio>
#include <bitset>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <fstream>
#include <cstring>
#include <cassert>
#include <numeric>
#include <set>
#include <map>
#include <deque>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <string>
#include <iostream>
#include <algorithm>
#include <functional>
#include <iomanip>

constexpr int N = 1e5 + 5;
int a[N], f[N << 2][10];
using LL = long long;
LL s[N << 2][10];
LL answer[10];

template<class T>
void in(T& x) {
  char c;
  while (!isdigit(c = getchar()) && c != '-');
  bool flag = (c == '-');
  if (flag) c = getchar();
  x = c - '0';
  while (isdigit(c = getchar())) x = x * 10 + c - '0';
  if (flag) x *= -1;
}

template<class T>
void out(T x) {
  if (x < 0) putchar('-'), x *= -1;
  int length = 0, bit[20];
  for (; x > 0; x /= 10) bit[length++] = x % 10;
  if (!length) bit[length++] = 0;
  while (length--) putchar(bit[length] + '0');
  putchar('\n');
}

int ql, qr, from, to;

#define L (x << 1)
#define R (x << 1 | 1)
#define MID ((l + r) >> 1)
#define LC L, l, MID
#define RC R, MID + 1, r

void merge(int x, int l, int r) {
  for (int i = 0; i < 10; ++i) {
    s[x][i] = s[L][i] + s[R][i];
    f[x][i] = i;
  }
}

void build(int x, int l, int r) {
  if (l == r) {
    for (int i = 0; i < 10; ++i) s[x][i] = 0, f[x][i] = i;
    LL now = 1;
    while (a[l]) {
      int d = a[l] % 10;
      s[x][d] += now;
      now *= 10;
      a[l] /= 10;
    }
  } else {
    build(LC), build(RC);
    merge(x, l, r);
  }
}

void combine(int *a, int *b, int *c) {
  for (int i = 0; i < 10; ++i) {
    c[i] = b[a[i]];
  }
}

void push(int x, int l, int r) {
  if (l == r) return ;

  static LL sum[10];
  static int tmp[10];
  for (int i = 0; i < 10; ++i) sum[i] = 0;
  for (int i = 0; i < 10; ++i) {
    sum[f[x][i]] += s[L][i];
  }
  for (int i = 0; i < 10; ++i) {
    s[L][i] = sum[i];
  }
  combine(f[L], f[x], tmp);
  for (int i = 0; i < 10; ++i) f[L][i] = tmp[i];

  for (int i = 0; i < 10; ++i) sum[i] = 0;
  for (int i = 0; i < 10; ++i) {
    sum[f[x][i]] += s[R][i];
  }
  for (int i = 0; i < 10; ++i) {
    s[R][i] = sum[i];
  }
  combine(f[R], f[x], tmp);
  for (int i = 0; i < 10; ++i) f[R][i] = tmp[i];
}

void update(int x, int l, int r) {
  if (ql <= l && qr >= r) {
    static int A[10], B[10];
    for (int i = 0; i < 10; ++i) A[i] = i;
    s[x][to] += s[x][from];
    s[x][from] = 0;
    A[from] = to;
    combine(f[x], A, B);
    for (int i = 0; i < 10; ++i) f[x][i] = B[i];
  } else {
    push(x, l, r);
    if (ql <= MID) update(LC);
    if (qr > MID) update(RC);
    merge(x, l, r);
  }
}

void query(int x, int l, int r) {
  if (ql <= l && qr >= r) {
    for (int i = 0; i < 10; ++i) answer[i] += s[x][i];
  } else {
    push(x, l, r);
    if (ql <= MID) query(LC);
    if (qr > MID) query(RC);
    merge(x, l, r);
  }
}

int main() {
  std::cerr << "[Line #" << __LINE__ << "] fuck !!!" << std::endl;
  int n, q;
  std::cin >> n >> q;
  for (int i = 0; i < n; ++i) in(a[i + 1]);
  build(1, 1, n);
  for (int i = 0; i < q; ++i) {
    int type;
    in(type), in(ql), in(qr);
    if (type == 1) {
      in(from), in(to);
      if (from == to) continue;
      update(1, 1, n);
    } else {
      for (int i = 0; i < 10; ++i) answer[i] = 0;
      query(1, 1, n);
      LL ans = 0;
      for (int i = 0; i < 10; ++i) ans += i * answer[i];
      out(ans);
    }
  }

  return 0;
}


/*************************************************************************
  >         File: E.cc
  >       Author: Yuan Lei
  >         Mail: yuanlei@indeed.com
  > Created Time: Sat May 13 19:42:08 2017
*************************************************************************/
#include <vector>
#include <cstdio>
#include <bitset>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <fstream>
#include <cstring>
#include <cassert>
#include <numeric>
#include <set>
#include <map>
#include <deque>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <string>
#include <iostream>
#include <algorithm>
#include <functional>
#include <iomanip>

constexpr int N = 1e5 + 5;
int a[N], f[N << 2][10];
using LL = long long;
LL s[N << 2][10];
LL answer[10];

template<class T>
void in(T& x) {
  char c;
  while (!isdigit(c = getchar()) && c != '-');
  bool flag = (c == '-');
  if (flag) c = getchar();
  x = c - '0';
  while (isdigit(c = getchar())) x = x * 10 + c - '0';
  if (flag) x *= -1;
}

template<class T>
void out(T x) {
  if (x < 0) putchar('-'), x *= -1;
  int length = 0, bit[20];
  for (; x > 0; x /= 10) bit[length++] = x % 10;
  if (!length) bit[length++] = 0;
  while (length--) putchar(bit[length] + '0');
  putchar('\n');
}

int ql, qr, from, to;

#define L (x << 1)
#define R (x << 1 | 1)
#define MID ((l + r) >> 1)
#define LC L, l, MID
#define RC R, MID + 1, r

void merge(int x, int l, int r) {
  for (int i = 0; i < 10; ++i) {
    s[x][i] = s[L][i] + s[R][i];
    f[x][i] = i;
  }
}

void build(int x, int l, int r) {
  if (l == r) {
    for (int i = 0; i < 10; ++i) s[x][i] = 0, f[x][i] = i;
    LL now = 1;
    while (a[l]) {
      int d = a[l] % 10;
      s[x][d] += now;
      now *= 10;
      a[l] /= 10;
    }
  } else {
    build(LC), build(RC);
    merge(x, l, r);
  }
}

void combine(int *a, int *b, int *c) {
  for (int i = 0; i < 10; ++i) {
    c[i] = b[a[i]];
  }
}

void push(int x, int l, int r) {
  if (l == r) return ;

  static LL sum[10];
  static int tmp[10];
  for (int i = 0; i < 10; ++i) sum[i] = 0;
  for (int i = 0; i < 10; ++i) {
    sum[f[x][i]] += s[L][i];
  }
  for (int i = 0; i < 10; ++i) {
    s[L][i] = sum[i];
  }
  combine(f[L], f[x], tmp);
  for (int i = 0; i < 10; ++i) f[L][i] = tmp[i];

  for (int i = 0; i < 10; ++i) sum[i] = 0;
  for (int i = 0; i < 10; ++i) {
    sum[f[x][i]] += s[R][i];
  }
  for (int i = 0; i < 10; ++i) {
    s[R][i] = sum[i];
  }
  combine(f[R], f[x], tmp);
  for (int i = 0; i < 10; ++i) f[R][i] = tmp[i];
}

void update(int x, int l, int r) {
  if (ql <= l && qr >= r) {
    static int A[10], B[10];
    for (int i = 0; i < 10; ++i) A[i] = i;
    s[x][to] += s[x][from];
    s[x][from] = 0;
    A[from] = to;
    combine(f[x], A, B);
    for (int i = 0; i < 10; ++i) f[x][i] = B[i];
  } else {
    push(x, l, r);
    if (ql <= MID) update(LC);
    if (qr > MID) update(RC);
    merge(x, l, r);
  }
}

void query(int x, int l, int r) {
  if (ql <= l && qr >= r) {
    for (int i = 0; i < 10; ++i) answer[i] += s[x][i];
  } else {
    push(x, l, r);
    if (ql <= MID) query(LC);
    if (qr > MID) query(RC);
    merge(x, l, r);
  }
}

int main() {
  //std::ios::sync_with_stdio(0);
  int n, q;
  //std::cin >> n >> q;
  in(n), in(q);
  for (int i = 0; i < n; ++i) in(a[i + 1]);
  build(1, 1, n);
  for (int i = 0; i < q; ++i) {
    int type;
    in(type), in(ql), in(qr);
    if (type == 1) {
      in(from), in(to);
      update(1, 1, n);
    } else {
      for (int i = 0; i < 10; ++i) answer[i] = 0;
      query(1, 1, n);
      LL ans = 0;
      for (int i = 0; i < 10; ++i) ans += i * answer[i];
      //std::cout << ans << std::endl;
      out(ans);
    }
  }

  return 0;
}


/*************************************************************************
  >         File: E.cc
  >       Author: Yuan Lei
  >         Mail: yuanlei@indeed.com
  > Created Time: Sat May 13 19:42:08 2017
*************************************************************************/
#include <vector>
#include <cstdio>
#include <bitset>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <fstream>
#include <cstring>
#include <cassert>
#include <numeric>
#include <set>
#include <map>
#include <deque>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <string>
#include <iostream>
#include <algorithm>
#include <functional>
#include <iomanip>

constexpr int N = 1e5 + 5;
int a[N], f[N << 2][10];
using LL = long long;
LL s[N << 2][10];
LL answer[10];

template<class T>
void in(T& x) {
  char c;
  while (!isdigit(c = getchar()) && c != '-');
  bool flag = (c == '-');
  if (flag) c = getchar();
  x = c - '0';
  while (isdigit(c = getchar())) x = x * 10 + c - '0';
  if (flag) x *= -1;
}

template<class T>
void out(T x) {
  if (x < 0) putchar('-'), x *= -1;
  int length = 0, bit[20];
  for (; x > 0; x /= 10) bit[length++] = x % 10;
  if (!length) bit[length++] = 0;
  while (length--) putchar(bit[length] + '0');
  putchar('\n');
}

int ql, qr, from, to;

#define L (x << 1)
#define R (x << 1 | 1)
#define MID ((l + r) >> 1)
#define LC L, l, MID
#define RC R, MID + 1, r

void merge(int x, int l, int r) {
  for (int i = 0; i < 10; ++i) {
    s[x][i] = s[L][i] + s[R][i];
    f[x][i] = i;
  }
}

void build(int x, int l, int r) {
  if (l == r) {
    for (int i = 0; i < 10; ++i) s[x][i] = 0, f[x][i] = i;
    LL now = 1;
    while (a[l]) {
      int d = a[l] % 10;
      s[x][d] += now;
      now *= 10;
      a[l] /= 10;
    }
  } else {
    build(LC), build(RC);
    merge(x, l, r);
  }
}

void combine(int *a, int *b, int *c) {
  for (int i = 0; i < 10; ++i) {
    c[i] = b[a[i]];
  }
}

void push(int x, int l, int r) {
  if (l == r) return ;

  static LL sum[10];
  static int tmp[10];
  for (int i = 0; i < 10; ++i) sum[i] = 0;
  for (int i = 0; i < 10; ++i) {
    sum[f[x][i]] += s[L][i];
  }
  for (int i = 0; i < 10; ++i) {
    s[L][i] = sum[i];
  }
  combine(f[L], f[x], tmp);
  for (int i = 0; i < 10; ++i) f[L][i] = tmp[i];

  for (int i = 0; i < 10; ++i) sum[i] = 0;
  for (int i = 0; i < 10; ++i) {
    sum[f[x][i]] += s[R][i];
  }
  for (int i = 0; i < 10; ++i) {
    s[R][i] = sum[i];
  }
  combine(f[R], f[x], tmp);
  for (int i = 0; i < 10; ++i) f[R][i] = tmp[i];
}

void update(int x, int l, int r) {
  if (ql <= l && qr >= r) {
    static int A[10], B[10];
    for (int i = 0; i < 10; ++i) A[i] = i;
    s[x][to] += s[x][from];
    s[x][from] = 0;
    A[from] = to;
    combine(f[x], A, B);
    for (int i = 0; i < 10; ++i) f[x][i] = B[i];
  } else {
    push(x, l, r);
    if (ql <= MID) update(LC);
    if (qr > MID) update(RC);
    merge(x, l, r);
  }
}

void query(int x, int l, int r) {
  if (ql <= l && qr >= r) {
    for (int i = 0; i < 10; ++i) answer[i] += s[x][i];
  } else {
    push(x, l, r);
    if (ql <= MID) query(LC);
    if (qr > MID) query(RC);
    merge(x, l, r);
  }
}

int main() {
  #ifdef HOME
  freopen("F.in", "r", stdin);
  #endif
  int n, q;
  in(n), in(q);
  for (int i = 0; i < n; ++i) in(a[i + 1]);
  build(1, 1, n);
  for (int i = 0; i < q; ++i) {
    int type;
    in(type), in(ql), in(qr);
    if (type == 1) {
      in(from), in(to);
      if (from == to) continue;
      update(1, 1, n);
    } else {
      for (int i = 0; i < 10; ++i) answer[i] = 0;
      query(1, 1, n);
      LL ans = 0;
      for (int i = 0; i < 10; ++i) ans += i * answer[i];
      out(ans);
    }
  }

  return 0;
}


/*************************************************************************
  >         File: E.cc
  >       Author: Yuan Lei
  >         Mail: yuanlei@indeed.com
  > Created Time: Sat May 13 19:42:08 2017
*************************************************************************/
#include <vector>
#include <cstdio>
#include <bitset>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <fstream>
#include <cstring>
#include <cassert>
#include <numeric>
#include <set>
#include <map>
#include <deque>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <string>
#include <iostream>
#include <algorithm>
#include <functional>
#include <iomanip>

constexpr int N = 1e5 + 5;
int a[N], f[N << 2][10];
using LL = long long;
LL s[N << 2][10];
LL answer[10];

template<class T>
void in(T& x) {
  char c;
  while (!isdigit(c = getchar()) && c != '-');
  bool flag = (c == '-');
  if (flag) c = getchar();
  x = c - '0';
  while (isdigit(c = getchar())) x = x * 10 + c - '0';
  if (flag) x *= -1;
}

template<class T>
void out(T x) {
  if (x < 0) putchar('-'), x *= -1;
  int length = 0, bit[20];
  for (; x > 0; x /= 10) bit[length++] = x % 10;
  if (!length) bit[length++] = 0;
  while (length--) putchar(bit[length] + '0');
  putchar('\n');
}

int ql, qr, from, to;

#define L (x << 1)
#define R (x << 1 | 1)
#define MID ((l + r) >> 1)
#define LC L, l, MID
#define RC R, MID + 1, r

void merge(int x, int l, int r) {
  for (int i = 0; i < 10; ++i) {
    s[x][i] = s[L][i] + s[R][i];
    f[x][i] = i;
  }
}

void build(int x, int l, int r) {
  if (l == r) {
    for (int i = 0; i < 10; ++i) s[x][i] = 0, f[x][i] = i;
    LL now = 1;
    while (a[l]) {
      int d = a[l] % 10;
      s[x][d] += now;
      now *= 10;
      a[l] /= 10;
    }
  } else {
    build(LC), build(RC);
    merge(x, l, r);
  }
}

void combine(int *a, int *b, int *c) {
  for (int i = 0; i < 10; ++i) {
    c[i] = b[a[i]];
  }
}

void push(int x, int l, int r) {
  if (l == r) return ;

  static LL sum[10];
  static int tmp[10];
  for (int i = 0; i < 10; ++i) sum[i] = 0;
  for (int i = 0; i < 10; ++i) {
    sum[f[x][i]] += s[L][i];
  }
  for (int i = 0; i < 10; ++i) {
    s[L][i] = sum[i];
  }
  combine(f[L], f[x], tmp);
  for (int i = 0; i < 10; ++i) f[L][i] = tmp[i];

  for (int i = 0; i < 10; ++i) sum[i] = 0;
  for (int i = 0; i < 10; ++i) {
    sum[f[x][i]] += s[R][i];
  }
  for (int i = 0; i < 10; ++i) {
    s[R][i] = sum[i];
  }
  combine(f[R], f[x], tmp);
  for (int i = 0; i < 10; ++i) f[R][i] = tmp[i];
}

void update(int x, int l, int r) {
  if (ql <= l && qr >= r) {
    static int A[10], B[10];
    for (int i = 0; i < 10; ++i) A[i] = i;
    s[x][to] += s[x][from];
    s[x][from] = 0;
    A[from] = to;
    combine(f[x], A, B);
    for (int i = 0; i < 10; ++i) f[x][i] = B[i];
  } else {
    push(x, l, r);
    if (ql <= MID) update(LC);
    if (qr > MID) update(RC);
    merge(x, l, r);
  }
}

void query(int x, int l, int r) {
  if (ql <= l && qr >= r) {
    for (int i = 0; i < 10; ++i) answer[i] += s[x][i];
  } else {
    push(x, l, r);
    if (ql <= MID) query(LC);
    if (qr > MID) query(RC);
    merge(x, l, r);
  }
}

int main() {
  std::ios::sync_with_stdio(0);
  int n, q;
  std::cin >> n >> q;
  for (int i = 0; i < n; ++i) in(a[i + 1]);
  build(1, 1, n);
  for (int i = 0; i < q; ++i) {
    int type;
    in(type), in(ql), in(qr);
    if (type == 1) {
      in(from), in(to);
      update(1, 1, n);
    } else {
      for (int i = 0; i < 10; ++i) answer[i] = 0;
      query(1, 1, n);
      LL ans = 0;
      for (int i = 0; i < 10; ++i) ans += i * answer[i];
      //std::cout << ans << std::endl;
      out(ans);
    }
  }

  return 0;
}


/*************************************************************************
  >         File: E.cc
  >       Author: Yuan Lei
  >         Mail: yuanlei@indeed.com
  > Created Time: Sat May 13 19:42:08 2017
*************************************************************************/
#include <vector>
#include <cstdio>
#include <bitset>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <fstream>
#include <cstring>
#include <cassert>
#include <numeric>
#include <set>
#include <map>
#include <deque>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <string>
#include <iostream>
#include <algorithm>
#include <functional>
#include <iomanip>

constexpr int N = 1e5 + 5;
int a[N], f[N << 2][10];
using LL = long long;
LL s[N << 2][10];
LL answer[10];

template<class T>
void in(T& x) {
  char c;
  while (!isdigit(c = getchar()) && c != '-');
  bool flag = (c == '-');
  if (flag) c = getchar();
  x = c - '0';
  while (isdigit(c = getchar())) x = x * 10 + c - '0';
  if (flag) x *= -1;
}

template<class T>
void out(T x) {
  if (x < 0) putchar('-'), x *= -1;
  int length = 0, bit[20];
  for (; x > 0; x /= 10) bit[length++] = x % 10;
  if (!length) bit[length++] = 0;
  while (length--) putchar(bit[length] + '0');
  putchar('\n');
}

int ql, qr, from, to;

#define L (x << 1)
#define R (x << 1 | 1)
#define MID ((l + r) >> 1)
#define LC L, l, MID
#define RC R, MID + 1, r

void merge(int x, int l, int r) {
  for (int i = 0; i < 10; ++i) {
    s[x][i] = s[L][i] + s[R][i];
    f[x][i] = i;
  }
}

void build(int x, int l, int r) {
  if (l == r) {
    for (int i = 0; i < 10; ++i) s[x][i] = 0, f[x][i] = i;
    LL now = 1;
    while (a[l]) {
      int d = a[l] % 10;
      s[x][d] += now;
      now *= 10;
      a[l] /= 10;
    }
  } else {
    build(LC), build(RC);
    merge(x, l, r);
  }
}

void combine(int *a, int *b, int *c) {
  for (int i = 0; i < 10; ++i) {
    c[i] = b[a[i]];
  }
}

void push(int x, int l, int r) {
  if (l == r) return ;

  static LL sum[10];
  static int tmp[10];
  for (int i = 0; i < 10; ++i) sum[i] = 0;
  for (int i = 0; i < 10; ++i) {
    sum[f[x][i]] += s[L][i];
  }
  for (int i = 0; i < 10; ++i) {
    s[L][i] = sum[i];
  }
  combine(f[L], f[x], tmp);
  for (int i = 0; i < 10; ++i) f[L][i] = tmp[i];

  for (int i = 0; i < 10; ++i) sum[i] = 0;
  for (int i = 0; i < 10; ++i) {
    sum[f[x][i]] += s[R][i];
  }
  for (int i = 0; i < 10; ++i) {
    s[R][i] = sum[i];
  }
  combine(f[R], f[x], tmp);
  for (int i = 0; i < 10; ++i) f[R][i] = tmp[i];
}

void update(int x, int l, int r) {
  if (ql <= l && qr >= r) {
    static int A[10], B[10];
    for (int i = 0; i < 10; ++i) A[i] = i;
    s[x][to] += s[x][from];
    s[x][from] = 0;
    A[from] = to;
    combine(f[x], A, B);
    for (int i = 0; i < 10; ++i) f[x][i] = B[i];
  } else {
    push(x, l, r);
    if (ql <= MID) update(LC);
    if (qr > MID) update(RC);
    merge(x, l, r);
  }
}

void query(int x, int l, int r) {
  if (ql <= l && qr >= r) {
    for (int i = 0; i < 10; ++i) answer[i] = 0;
    for (int i = 0; i < 10; ++i) answer[i] += s[x][i];
  } else {
    push(x, l, r);
    if (ql <= MID) query(LC);
    if (qr > MID) query(RC);
    merge(x, l, r);
  }
}

int main() {
  std::ios::sync_with_stdio(0);
  int n, q;
  std::cin >> n >> q;
  for (int i = 0; i < n; ++i) in(a[i + 1]);
  build(1, 1, n);
  for (int i = 0; i < q; ++i) {
    int type;
    in(type), in(ql), in(qr);
    if (type == 1) {
      in(from), in(to);
      update(1, 1, n);
    } else {
      query(1, 1, n);
      LL ans = 0;
      for (int i = 0; i < 10; ++i) ans += i * answer[i];
      std::cout << ans << std::endl;
    }
  }

  return 0;
}


/*************************************************************************
  >         File: E.cc
  >       Author: Yuan Lei
  >         Mail: yuanlei@indeed.com
  > Created Time: Sat May 13 19:42:08 2017
*************************************************************************/
#include <vector>
#include <cstdio>
#include <bitset>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <fstream>
#include <cstring>
#include <cassert>
#include <numeric>
#include <set>
#include <map>
#include <deque>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <string>
#include <iostream>
#include <algorithm>
#include <functional>
#include <iomanip>

constexpr int N = 1e5 + 5;
int a[N], f[N << 2][10];
using LL = long long;
LL s[N << 2][10];
LL answer[10];

template<class T>
void in(T& x) {
  char c;
  while (!isdigit(c = getchar()) && c != '-');
  bool flag = (c == '-');
  if (flag) c = getchar();
  x = c - '0';
  while (isdigit(c = getchar())) x = x * 10 + c - '0';
  if (flag) x *= -1;
}

template<class T>
void out(T x) {
  if (x < 0) putchar('-'), x *= -1;
  int length = 0, bit[20];
  for (; x > 0; x /= 10) bit[length++] = x % 10;
  if (!length) bit[length++] = 0;
  while (length--) putchar(bit[length] + '0');
  putchar('\n');
}

int ql, qr, from, to;

#define L (x << 1)
#define R (x << 1 | 1)
#define MID ((l + r) >> 1)
#define LC L, l, MID
#define RC R, MID + 1, r

void merge(int x, int l, int r) {
  for (int i = 0; i < 10; ++i) {
    s[x][i] = s[L][i] + s[R][i];
    f[x][i] = i;
  }
}

void build(int x, int l, int r) {
  if (l == r) {
    for (int i = 0; i < 10; ++i) s[x][i] = 0, f[x][i] = i;
    LL now = 1;
    while (a[l]) {
      int d = a[l] % 10;
      s[x][d] += now;
      now *= 10;
      a[l] /= 10;
    }
  } else {
    build(LC), build(RC);
    merge(x, l, r);
  }
}

void combine(int *a, int *b, int *c) {
  for (int i = 0; i < 10; ++i) {
    c[i] = b[a[i]];
  }
}

void push(int x, int l, int r) {
  if (l == r) return ;

  static LL sum[10];
  static int tmp[10];
  for (int i = 0; i < 10; ++i) sum[i] = 0;
  for (int i = 0; i < 10; ++i) {
    sum[f[x][i]] += s[L][i];
  }
  for (int i = 0; i < 10; ++i) {
    s[L][i] = sum[i];
  }
  combine(f[L], f[x], tmp);
  for (int i = 0; i < 10; ++i) f[L][i] = tmp[i];

  for (int i = 0; i < 10; ++i) sum[i] = 0;
  for (int i = 0; i < 10; ++i) {
    sum[f[x][i]] += s[R][i];
  }
  for (int i = 0; i < 10; ++i) {
    s[R][i] = sum[i];
  }
  combine(f[R], f[x], tmp);
  for (int i = 0; i < 10; ++i) f[R][i] = tmp[i];
}

void update(int x, int l, int r) {
  if (ql <= l && qr >= r) {
    static int A[10], B[10];
    for (int i = 0; i < 10; ++i) A[i] = i;
    s[x][to] += s[x][from];
    s[x][from] = 0;
    A[from] = to;
    combine(f[x], A, B);
    for (int i = 0; i < 10; ++i) f[x][i] = B[i];
  } else {
    push(x, l, r);
    if (ql <= MID) update(LC);
    if (qr > MID) update(RC);
    merge(x, l, r);
  }
}

void query(int x, int l, int r) {
  if (ql <= l && qr >= r) {
    for (int i = 0; i < 10; ++i) answer[i] += s[x][i];
  } else {
    push(x, l, r);
    if (ql <= MID) query(LC);
    if (qr > MID) query(RC);
    merge(x, l, r);
  }
}

int main() {
  std::ios::sync_with_stdio(0);
  int n, q;
  std::cin >> n >> q;
  for (int i = 0; i < n; ++i) in(a[i + 1]);
  build(1, 1, n);
  std::cerr << "[Line #" << __LINE__ << "] fuck !!!" << std::endl;
  for (int i = 0; i < q; ++i) {
    int type;
    in(type), in(ql), in(qr);
    if (type == 1) {
      in(from), in(to);
      update(1, 1, n);
    } else {
      for (int i = 0; i < 10; ++i) answer[i] = 0;
      query(1, 1, n);
      LL ans = 0;
      for (int i = 0; i < 10; ++i) ans += i * answer[i];
      std::cout << ans << std::endl;
    }
  }

  return 0;
}


#include<bits/stdc++.h>
#define NN 100100
#define ls (u<<1)
#define rs (ls|1)
#define mid (l+r>>1)

using namespace std;
using INT=long long ;
int a[NN];
int flag[NN<<2][11];
INT sum[NN<<2][11];

void push_up(int u) {
	for(int i=0; i<10; i++) sum[u][i]=sum[ls][i]+sum[rs][i];
}

void build(int u, int l, int r) {
	for(int i=0; i<10; i++) flag[u][i]=i;
	if(l+1==r) {
		int tmp=1, x=a[l];
		while(x) {
			int d=x%10;
			sum[u][d]+=tmp;
			tmp*=10;
			x/=10;
		}
		return ;
	}
	build(ls, l, mid);
	build(rs, mid, r);
	push_up(u);
}

INT arr[11];

void push_down(int u) {
	memset(arr, 0, sizeof arr);
	for(int i=0; i<10; i++) arr[i]=sum[ls][i], sum[ls][i]=0;
	for(int i=0; i<10; i++) {
		flag[ls][i]=flag[u][flag[ls][i]];
		sum[ls][flag[ls][i]]+=arr[i];
	}
	for(int i=0; i<10; i++) arr[i]=sum[rs][i], sum[rs][i]=0;
	for(int i=0; i<10; i++) {
		flag[rs][i]=flag[u][flag[rs][i]];
		sum[rs][flag[rs][i]]+=arr[i];
	}
	for(int i=0; i<10; i++) flag[u][i]=i;
}

void update(int u, int l, int r, int st, int ed, int x, int y) {
	if(l>=ed or r<=st) return ;
	if(l>=st && r<=ed) {
		INT tmp=0;
		for(int i=0; i<10; i++) {
			if(flag[u][i]==x) {
				flag[u][i]=y;
				tmp+=sum[u][i];
				sum[u][i]=0;
			}
		}
		sum[u][y]+=tmp;
		flag[u][y]=y;
		return ;
	}
	push_down(u);
	update(ls, l, mid, st, ed, x, y);
	update(rs, mid, r, st, ed, x, y);
	push_up(u);
}

INT calc(int u, int l, int r, int st, int ed) {
	if(l>=ed or r<=st) return 0;
	if(l>=st && r<=ed) {
		INT tmp=0;
		for(int i=0; i<10; i++) {
			tmp+=i*sum[u][i];
		}
		return tmp;
	}
	push_down(u);
	return calc(ls, l, mid, st, ed)+calc(rs, mid, r, st, ed);
}

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif

	int n, q;
	cin>>n>>q;
	for(int i=1; i<=n; i++) scanf("%d", &a[i]);
	build(1, 1, n+1);
	while(q--) {
		int t; scanf("%d", &t);
		if(t==1) {
			int l, r, x, y;
			scanf("%d %d %d %d", &l, &r, &x, &y);
			update(1, 1, n+1, l, r+1, x, y);
		}else {
			int l, r;
			scanf("%d %d", &l, &r);
			INT ans=calc(1, 1, n+1, l, r+1);
			printf("%I64d\n", ans);
		}
	}

	return 0;
}


#include<bits/stdc++.h>
#define NN 100100
#define ls (u<<1)
#define rs (ls|1)
#define mid (l+r>>1)

using namespace std;
using INT=long long ;
int a[NN];
int flag[NN<<2][11];
INT sum[NN<<2][11];

void push_up(int u) {
	for(int i=0; i<10; i++) sum[u][i]=sum[ls][i]+sum[rs][i];
}

void build(int u, int l, int r) {
	for(int i=0; i<10; i++) flag[u][i]=i;
	if(l+1==r) {
		int tmp=1, x=a[l];
		while(x) {
			int d=x%10;
			sum[u][d]+=tmp;
			tmp*=10;
			x/=10;
		}
		return ;
	}
	build(ls, l, mid);
	build(rs, mid, r);
	push_up(u);
}

INT arr[11];

void push_down(int u) {
	memset(arr, 0, sizeof arr);
	for(int i=0; i<10; i++) arr[flag[u][i]]+=sum[ls][i];
	for(int i=0; i<10; i++) {
		flag[ls][i]=flag[u][flag[ls][i]];
		sum[ls][i]=arr[i];
	}
	memset(arr, 0, sizeof arr);
	for(int i=0; i<10; i++) arr[flag[u][i]]+=sum[rs][i];
	for(int i=0; i<10; i++) {
		flag[rs][i]=flag[u][flag[rs][i]];
		sum[rs][i]=arr[i];
	}
	for(int i=0; i<10; i++) flag[u][i]=i;
}

void update(int u, int l, int r, int st, int ed, int x, int y) {
	if(l>=ed or r<=st) return ;
	if(l>=st && r<=ed) {
		for(int i=0; i<10; i++) {
			if(flag[u][i]==x) {
				flag[u][i]=y;
			}
		}
		INT tmp=sum[u][x];
		sum[u][x]=0;
		sum[u][y]+=tmp;
		return ;
	}
	push_down(u);
	update(ls, l, mid, st, ed, x, y);
	update(rs, mid, r, st, ed, x, y);
	push_up(u);
}

INT calc(int u, int l, int r, int st, int ed) {
	if(l>=ed or r<=st) return 0;
	if(l>=st && r<=ed) {
		INT tmp=0;
		for(int i=0; i<10; i++) {
			tmp+=i*sum[u][i];
		}
		return tmp;
	}
	push_down(u);
	return calc(ls, l, mid, st, ed)+calc(rs, mid, r, st, ed);
}

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif

	int n, q;
	cin>>n>>q;
	for(int i=1; i<=n; i++) scanf("%d", &a[i]);
	build(1, 1, n+1);
	while(q--) {
		int t; scanf("%d", &t);
		if(t==1) {
			int l, r, x, y;
			scanf("%d %d %d %d", &l, &r, &x, &y);
			update(1, 1, n+1, l, r+1, x, y);
		}else {
			int l, r;
			scanf("%d %d", &l, &r);
			INT ans=calc(1, 1, n+1, l, r+1);
			printf("%I64d\n", ans);
		}
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
using INT=long long;
const int NN=272727;
INT d[NN][10],E[10];
int fl[NN][10],a[NN];

#define ls (u<<1)
#define rs (ls|1)
#define mid (l+r>>1)
void push_up(int u){
	for(int i=0;i<10;i++) d[u][i]=d[ls][i]+d[rs][i];
}
void build(int u,int l,int r){
	for(int i=0;i<10;i++) fl[u][i]=i;
	if(l+1==r){
		int e=a[l];
		int l=0;
		while(e){
			int v=e%10;
			d[u][v]+=E[l++];
			e/=10;
		}
		return;
	}
	build(ls,l,mid);
	build(rs,mid,r);
	push_up(u);
}
void push_down(int u){
	for(int i=0;i<10;i++){
		fl[ls][i]=fl[u][fl[ls][i]];
	}
	for(int i=0;i<10;i++){
		fl[rs][i]=fl[u][fl[rs][i]];
	}

	for(int i=0;i<10;i++){
		if(d[ls][i] and fl[ls][i]!=i) d[ls][fl[ls][i]]+=d[ls][i],d[ls][i]=0;
	}
	for(int i=0;i<10;i++){
		if(d[rs][i] and fl[rs][i]!=i) d[rs][fl[rs][i]]+=d[rs][i],d[rs][i]=0;
	}

	for(int i=0;i<10;i++) fl[u][i]=i;
}
void change(int u,int l,int r,int st,int ed,int x,int y){
	if(r<=st or ed<=l) return;
	if(st<=l and r<=ed){
		if(d[u][x]==0) return;
		fl[u][x]=y;
		d[u][y]+=d[u][x];
		d[u][x]=0;
		return;
	}
	push_down(u);
	change(ls,l,mid,st,ed,x,y);
	change(rs,mid,r,st,ed,x,y);
	push_up(u);
}
INT calc(int u,int l,int r,int st,int ed){
	if(r<=st or ed<=l) return 0;
	if(st<=l and r<=ed) {
		INT A=0;
		for(int i=0;i<10;i++) A+=1LL*i*d[u][i];
		return A;
	}
	push_down(u);
	return calc(ls,l,mid,st,ed)+calc(rs,mid,r,st,ed);
}
int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	E[0]=1;
	for(int i=1;i<=10;i++) E[i]=E[i-1]*10;

	int n,q;
	scanf("%d%d",&n,&q);
	for(int i=1;i<=n;i++) scanf("%d",a+i);
	build(1,1,n+1);
	for(int i=1;i<=q;i++){
		int ca;
		scanf("%d",&ca);
		if(ca==1){
			int st,ed,x,y;
			scanf("%d%d%d%d",&st,&ed,&x,&y);
			if(x!=y) change(1,1,n+1,st,ed+1,x,y);
		}
		else {
			int st,ed;
			scanf("%d%d",&st,&ed);
			INT ans=calc(1,1,n+1,st,ed+1);
			printf("%I64d\n",ans);
		}
	}
	return 0;
}


#include<bits/stdc++.h>
#define NN 100100
#define ls (u<<1)
#define rs (ls|1)
#define mid (l+r>>1)

using namespace std;
using INT=long long ;
int a[NN];
int flag[NN<<2][11];
INT sum[NN<<2][11];

void push_up(int u) {
	for(int i=0; i<10; i++) sum[u][i]=sum[ls][i]+sum[rs][i];
}

void build(int u, int l, int r) {
	for(int i=0; i<10; i++) flag[u][i]=i;
	if(l+1==r) {
		int tmp=1, x=a[l];
		while(x) {
			int d=x%10;
			sum[u][d]+=tmp;
			tmp*=10;
			x/=10;
		}
		return ;
	}
	build(ls, l, mid);
	build(rs, mid, r);
	push_up(u);
}

INT arr[11];

void push_down(int u) {
	for(int i=0; i<10; i++) arr[i]=sum[ls][i], sum[ls][i]=0;
	for(int i=0; i<10; i++) {
		flag[ls][i]=flag[u][flag[ls][i]];
		sum[ls][flag[ls][i]]+=arr[i];
	}
	for(int i=0; i<10; i++) arr[i]=sum[rs][i], sum[rs][i]=0;
	for(int i=0; i<10; i++) {
		flag[rs][i]=flag[u][flag[rs][i]];
		sum[rs][flag[rs][i]]+=arr[i];
	}
	for(int i=0; i<10; i++) flag[u][i]=i;
}

void update(int u, int l, int r, int st, int ed, int x, int y) {
	if(l>=ed or r<=st) return ;
	if(l>=st && r<=ed) {
		INT tmp=0;
		for(int i=0; i<10; i++) {
			if(flag[u][i]==x) {
				flag[u][i]=y;
				tmp+=sum[u][i];
				sum[u][i]=0;
			}
		}
		sum[u][y]+=tmp;
		return ;
	}
	push_down(u);
	update(ls, l, mid, st, ed, x, y);
	update(rs, mid, r, st, ed, x, y);
	push_up(u);
}

INT calc(int u, int l, int r, int st, int ed) {
	if(l>=ed or r<=st) return 0;
	if(l>=st && r<=ed) {
		INT tmp=0;
		for(int i=0; i<10; i++) tmp+=i*sum[u][i];
		return tmp;
	}
	push_down(u);
	return calc(ls, l, mid, st, ed)+calc(rs, mid, r, st, ed);
}

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif

	int n, q;
	cin>>n>>q;
	for(int i=1; i<=n; i++) scanf("%d", &a[i]);
	build(1, 1, n+1);
	while(q--) {
		int t; scanf("%d", &t);
		if(t==1) {
			int l, r, x, y;
			scanf("%d %d %d %d", &l, &r, &x, &y);
			update(1, 1, n+1, l, r+1, x, y);
		}else {
			int l, r;
			scanf("%d %d", &l, &r);
			INT ans=calc(1, 1, n+1, l, r+1);
			printf("%I64d\n", ans);
		}
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
using INT=long long;
const int NN=272727;
INT d[NN][10],E[10];
int fl[NN][10],a[NN];

#define ls (u<<1)
#define rs (ls|1)
#define mid (l+r>>1)
void push_up(int u){
	for(int i=0;i<10;i++) d[u][i]=d[ls][i]+d[rs][i];
}
void build(int u,int l,int r){
	for(int i=0;i<10;i++) fl[u][i]=i;
	if(l+1==r){
		int e=a[l];
		int l=0;
		while(e){
			int v=e%10;
			d[u][v]+=E[l++];
			e/=10;
		}
		return;
	}
	build(ls,l,mid);
	build(rs,mid,r);
	push_up(u);
}
void push_down(int u){
	for(int i=0;i<10;i++){
		fl[ls][i]=fl[u][fl[ls][i]];
	}
	for(int i=0;i<10;i++){
		fl[rs][i]=fl[u][fl[rs][i]];
	}

	for(int i=0;i<10;i++){
		if(d[ls][i] and fl[ls][i]!=i) d[ls][fl[ls][i]]+=d[ls][i],d[ls][i]=0;
	}
	for(int i=0;i<10;i++){
		if(d[rs][i] and fl[rs][i]!=i) d[rs][fl[rs][i]]+=d[rs][i],d[rs][i]=0;
	}
}
void change(int u,int l,int r,int st,int ed,int x,int y){
	if(r<=st or ed<=l) return;
	if(st<=l and r<=ed){
		if(d[u][x]==0) return;
		fl[u][x]=y;
		d[u][y]+=d[u][x];
		d[u][x]=0;
		return;
	}
	push_down(u);
	change(ls,l,mid,st,ed,x,y);
	change(rs,mid,r,st,ed,x,y);
	push_up(u);
}
INT calc(int u,int l,int r,int st,int ed){
	if(r<=st or ed<=l) return 0;
	if(st<=l and r<=ed) {
		INT A=0;
		for(int i=0;i<10;i++) A+=1LL*i*d[u][i];
		return A;
	}
	push_down(u);
	return calc(ls,l,mid,st,ed)+calc(rs,mid,r,st,ed);
}
int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	E[0]=1;
	for(int i=1;i<=10;i++) E[i]=E[i-1]*10;

	int n,q;
	scanf("%d%d",&n,&q);
	for(int i=1;i<=n;i++) scanf("%d",a+i);
	build(1,1,n+1);
	for(int i=1;i<=q;i++){
		int ca;
		scanf("%d",&ca);
		if(ca==1){
			int st,ed,x,y;
			scanf("%d%d%d%d",&st,&ed,&x,&y);
			if(x!=y) change(1,1,n+1,st,ed+1,x,y);
		}
		else {
			int st,ed;
			scanf("%d%d",&st,&ed);
			INT ans=calc(1,1,n+1,st,ed+1);
			printf("%I64d\n",ans);
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
using INT=long long;
const int NN=272727;
INT d[NN][10],E[10];
int fl[NN][10],a[NN];
#define ls (u<<1)
#define rs (ls|1)
#define mid (l+r>>1)
void push_up(int u){
	for(int i=0;i<10;i++) d[u][i]=d[ls][i]+d[rs][i];
}
void build(int u,int l,int r){
	for(int i=0;i<10;i++) fl[u][i]=i;
	if(l+1==r){
		int e=a[l];
		int l=0;
		while(e){
			int v=e%10;
			d[u][v]+=E[l++];
			e/=10;
		}
		return;
	}
	build(ls,l,mid);
	build(rs,mid,r);
	push_up(u);
}
void push_down(int u){
	INT s[2][10];
	for(int i=0;i<10;i++) s[0][i]=s[1][i]=0;

	for(int i=0;i<10;i++){
		if(fl[u][i]!=i) s[0][fl[u][i]]+=d[ls][i],d[ls][i]=0;
		else s[0][i]+=d[ls][i];
	}
	for(int i=0;i<10;i++) d[ls][i]=s[0][i];

	for(int i=0;i<10;i++){
		if(fl[u][i]!=i) s[1][fl[u][i]]+=d[rs][i],d[rs][i]=0;
		else s[1][i]+=d[rs][i];
	}
	for(int i=0;i<10;i++) d[rs][i]=s[1][i];

	for(int i=0;i<10;i++){
		fl[ls][i]=fl[u][fl[ls][i]];
	}
	for(int i=0;i<10;i++){
		fl[rs][i]=fl[u][fl[rs][i]];
	}

	for(int i=0;i<10;i++) fl[u][i]=i;
}
void change(int u,int l,int r,int st,int ed,int x,int y){
	if(r<=st or ed<=l) return;
	if(st<=l and r<=ed){
		if(d[u][x]==0) return;
//		push_down(u);
		for(int i=0;i<10;i++) if(fl[u][i]==x) fl[u][i]=y;
		d[u][y]+=d[u][x];
		d[u][x]=0;
		return;
	}
	push_down(u);
	change(ls,l,mid,st,ed,x,y);
	change(rs,mid,r,st,ed,x,y);
	push_up(u);
}
INT calc(int u,int l,int r,int st,int ed){
	if(r<=st or ed<=l) return 0;
	if(st<=l and r<=ed) {
		INT A=0;
		for(int i=0;i<10;i++) {
			A+=1LL*i*d[u][i];
		}
		return A;
	}
	push_down(u);
	return calc(ls,l,mid,st,ed)+calc(rs,mid,r,st,ed);
}
int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	E[0]=1;
	for(int i=1;i<=10;i++) E[i]=E[i-1]*10;

	int n,q;
	scanf("%d%d",&n,&q);
	for(int i=1;i<=n;i++) scanf("%d",a+i);
	build(1,1,n+1);
	for(int i=1;i<=q;i++){
		int ca;
		scanf("%d",&ca);
		if(ca==1){
			int st,ed,x,y;
			scanf("%d%d%d%d",&st,&ed,&x,&y);
			if(x!=y) change(1,1,n+1,st,ed+1,x,y);
		}
		else {
			int st,ed;
			scanf("%d%d",&st,&ed);
			INT ans=calc(1,1,n+1,st,ed+1);
			printf("%I64d\n",ans);
		}
	}
	return 0;
}


#include<bits/stdc++.h>
#define NN 100100
#define ls (u<<1)
#define rs (ls|1)
#define mid (l+r>>1)

using namespace std;
using INT=long long ;
int a[NN];
int flag[NN<<2][11];
INT sum[NN<<2][11];

void push_up(int u) {
	for(int i=0; i<10; i++) sum[u][i]=sum[ls][i]+sum[rs][i];
}

void build(int u, int l, int r) {
	for(int i=0; i<10; i++) flag[u][i]=i;
	if(l+1==r) {
		int tmp=1, x=a[l];
		while(x) {
			int d=x%10;
			sum[u][d]+=tmp;
			tmp*=10;
			x/=10;
		}
		return ;
	}
	build(ls, l, mid);
	build(rs, mid, r);
	push_up(u);
}

INT arr[11];

void push_down(int u) {
	for(int i=0; i<10; i++) arr[i]=sum[ls][i], sum[ls][i]=0;
	for(int i=0; i<10; i++) {
		flag[ls][i]=flag[u][flag[ls][i]];
		sum[ls][flag[ls][i]]+=arr[i];
	}
	for(int i=0; i<10; i++) arr[i]=sum[rs][i], sum[rs][i]=0;
	for(int i=0; i<10; i++) {
		flag[rs][i]=flag[u][flag[rs][i]];
		sum[rs][flag[rs][i]]+=arr[i];
	}
	for(int i=0; i<10; i++) flag[u][i]=i;
}

void update(int u, int l, int r, int st, int ed, int x, int y) {
	if(l>=ed or r<=st) return ;
	if(l>=st && r<=ed) {
		for(int i=0; i<10; i++) {
			if(flag[u][i]==x) {
				flag[u][i]=y;
			}
		}
		sum[u][y]+=sum[u][x];
		sum[u][x]=0;
		return ;
	}
	push_down(u);
	update(ls, l, mid, st, ed, x, y);
	update(rs, mid, r, st, ed, x, y);
	push_up(u);
}

INT calc(int u, int l, int r, int st, int ed) {
	if(l>=ed or r<=st) return 0;
	if(l>=st && r<=ed) {
		INT tmp=0;
		for(int i=0; i<10; i++) tmp+=i*sum[u][i];
		return tmp;
	}
	push_down(u);
	return calc(ls, l, mid, st, ed)+calc(rs, mid, r, st, ed);
}

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif

	int n, q;
	cin>>n>>q;
	for(int i=1; i<=n; i++) scanf("%d", &a[i]);
	build(1, 1, n+1);
	while(q--) {
		int t; scanf("%d", &t);
		if(t==1) {
			int l, r, x, y;
			scanf("%d %d %d %d", &l, &r, &x, &y);
			update(1, 1, n+1, l, r+1, x, y);
		}else {
			int l, r;
			scanf("%d %d", &l, &r);
			INT ans=calc(1, 1, n+1, l, r+1);
			printf("%I64d\n", ans);
		}
	}

	return 0;
}


#include<bits/stdc++.h>
#define NN 100100
#define ls (u<<1)
#define rs (ls|1)
#define mid (l+r>>1)

using namespace std;
using INT=long long ;
int a[NN], pw[20];
int flag[NN<<2][11];
INT sum[NN<<2][11];

void push_up(int u) {
	for(int i=0; i<10; i++) sum[u][i]=sum[ls][i]+sum[rs][i];
}

void build(int u, int l, int r) {
	for(int i=0; i<10; i++) flag[u][i]=i;
	if(l+1==r) {
		int tmp=1, x=a[l];
		while(x) {
			int d=x%10;
			sum[u][d]+=tmp;
			tmp*=10;
			x/=10;
		}
		return ;
	}
	build(ls, l, mid);
	build(rs, mid, r);
	push_up(u);
}

void push_down(int u) {
	for(int i=0; i<10; i++) {
		flag[ls][i]=flag[u][flag[ls][i]];
		flag[rs][i]=flag[u][flag[rs][i]];
		INT tmp=sum[ls][i];
		sum[ls][i]=0;
		sum[ls][flag[ls][i]]+=tmp;
		tmp=sum[rs][i];
		sum[rs][i]=0;
		sum[rs][flag[rs][i]]+=tmp;
	}
	for(int i=0; i<10; i++) flag[u][i]=i;
}

void update(int u, int l, int r, int st, int ed, int x, int y) {
	if(l>=ed or r<=st) return ;
	if(l>=st && r<=ed) {
		for(int i=0; i<10; i++) {
			if(flag[u][i]==x) {
				INT tmp=sum[u][i];
				flag[u][i]=y;
				sum[u][y]+=tmp;
				sum[u][i]=0;
			}
		}
		return ;
	}
	push_down(u);
	update(ls, l, mid, st, ed, x, y);
	update(rs, mid, r, st, ed, x, y);
	push_up(u);
}

INT calc(int u, int l, int r, int st, int ed) {
	if(l>=ed or r<=st) return 0;
	if(l>=st && r<=ed) {
		INT tmp=0;
		for(int i=0; i<10; i++) tmp+=i*sum[u][i];
		return tmp;
	}
	push_down(u);
	return calc(ls, l, mid, st, ed)+calc(rs, mid, r, st, ed);
}

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif
	pw[0]=1;
	for(int i=1; i<=9; i++) pw[i]=pw[i-1]*10;

	int n, q;
	cin>>n>>q;
	for(int i=1; i<=n; i++) scanf("%d", &a[i]);
	build(1, 1, n+1);

	while(q--) {
		int t; scanf("%d", &t);
		if(t==1) {
			int l, r, x, y;
			scanf("%d %d %d %d", &l, &r, &x, &y);
			update(1, 1, n+1, l, r+1, x, y);
		}else {
			int l, r;
			scanf("%d %d", &l, &r);
			INT ans=calc(1, 1, n+1, l, r+1);
			printf("%I64d\n", ans);
		}
	}

	return 0;
}


#include<bits/stdc++.h>
#define NN 100100
#define ls (u<<1)
#define rs (ls|1)
#define mid (l+r>>1)

using namespace std;
using INT=long long ;
int a[NN], pw[20];
int flag[NN<<2][11];
INT sum[NN<<2][11];

void push_up(int u) {
	for(int i=0; i<10; i++) sum[u][i]=sum[ls][i]+sum[rs][i];
}

void build(int u, int l, int r) {
	for(int i=0; i<10; i++) flag[u][i]=i;
	if(l+1==r) {
		int tmp=1, x=a[l];
		while(x) {
			int d=x%10;
			sum[u][d]+=tmp;
			tmp*=10;
			x/=10;
		}
		return ;
	}
	build(ls, l, mid);
	build(rs, mid, r);
	push_up(u);
}

void push_down(int u) {
	for(int i=0; i<10; i++) {
		flag[ls][i]=flag[u][flag[ls][i]];
		flag[rs][i]=flag[u][flag[rs][i]];
		INT tmp=sum[ls][i];
		sum[ls][i]=0;
		sum[ls][flag[ls][i]]+=tmp;
		tmp=sum[rs][i];
		sum[rs][i]=0;
		sum[rs][flag[rs][i]]+=tmp;
	}
	for(int i=0; i<10; i++) flag[u][i]=i;
}

void update(int u, int l, int r, int st, int ed, int x, int y) {
	if(l>=ed or r<=st) return ;
	if(l>=st && r<=ed) {
		for(int i=0; i<10; i++) {
			if(flag[u][i]==x) {
				INT tmp=sum[u][i];
				sum[u][i]=0;
				flag[u][i]=y;
				sum[u][y]+=tmp;
			}
		}
		return ;
	}
	push_down(u);
	update(ls, l, mid, st, ed, x, y);
	update(rs, mid, r, st, ed, x, y);
	push_up(u);
}

INT calc(int u, int l, int r, int st, int ed) {
	if(l>=ed or r<=st) return 0;
	if(l>=st && r<=ed) {
		INT tmp=0;
		for(int i=0; i<10; i++) tmp+=i*sum[u][i];
		return tmp;
	}
	push_down(u);
	return calc(ls, l, mid, st, ed)+calc(rs, mid, r, st, ed);
}

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif

	int n, q;
	cin>>n>>q;
	for(int i=1; i<=n; i++) scanf("%d", &a[i]);
	build(1, 1, n+1);

	while(q--) {
		int t; scanf("%d", &t);
		if(t==1) {
			int l, r, x, y;
			scanf("%d %d %d %d", &l, &r, &x, &y);
			update(1, 1, n+1, l, r+1, x, y);
		}else {
			int l, r;
			scanf("%d %d", &l, &r);
			INT ans=calc(1, 1, n+1, l, r+1);
			printf("%I64d\n", ans);
		}
	}

	return 0;
}


//#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define mp make_pair

typedef long long ll;
typedef unsigned long long int ull;
typedef long double ld;

typedef pair<int, int> pii;
typedef pair<ll, int> pli;

typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<int> vi;

typedef map<string, int> msi;
typedef map<int, int> mii;
typedef map<int, ll> mill;
typedef map<int, vi> mivi;

const int MAXN = 1e5;

int a[MAXN + 1];

ll tree[10][4 * MAXN + 1];
int lazy[10][4 * MAXN + 1];

int from, to;

void fast_io() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
}

void clean(int i, int v) {
	int pos = lazy[i][v];
	ll at = tree[i][v];

	tree[i][v] = 0;
	tree[pos][v] += at;

	lazy[i][v] = i;
}

void pushdown(int v, int tl, int tr) {
	if(tl != tr) {
		int L = (v << 1), R = (L | 1);
		for(int i = 0; i <= 9; i++) lazy[i][L] = lazy[lazy[i][L]][v];
		for(int i = 0; i <= 9; i++) lazy[i][R] = lazy[lazy[i][R]][v];
	}
	for(int i = 0; i <= 9; i++) clean(i, v);
}

void pushup(int v, int L, int R) {
	for(int i = 0; i < 10; i++)
			tree[i][v] = tree[i][L] + tree[i][R];
}

void build(int v, int l, int r) {
	for(int i = 0; i <= 9; i++) lazy[i][v] = i;
	if(l == r) {
		int tenp = 1, dig = a[l];
		for(int i = 0; dig; i++) {
			tree[dig % 10][v] += tenp;
			tenp *= 10;
			dig /= 10;
		}
	}
	else {
		int mid = (l + r) >> 1;
		int L = (v << 1), R = (L | 1);
		build(L, l, mid);
		build(R, mid + 1, r);
		pushup(v, L, R);
	}
}

void update(int v, int tl, int tr, int l, int r) {
	pushdown(v, tl, tr);
	if(l > tr or r < tl) return;
	if(l <= tl and r >= tr) {
		lazy[from][v] = to;
		pushdown(v, tl, tr);
	}
	else {
		int mid = (tl + tr) >> 1;
		int L = (v << 1), R = (L | 1);
		update(L, tl, mid, l, r);
		update(R, mid + 1, tr, l, r);
		pushup(v, L, R);
	}
}

ll total(int v) {
	ll res = 0;
	for(int i = 0; i <= 9; i++)
		res += (1LL * i * tree[i][v]);
	return res;
}

ll query(int v, int tl, int tr, int l, int r) {
	pushdown(v, tl, tr);
	if(l > tr or r < tl) return 0;
	if(l <= tl and r >= tr) return total(v);
	int mid = (tl + tr) >> 1;
	int L = (v << 1), R = (L | 1);
	return query(L, tl, mid, l, r) + query(R, mid + 1, tr, l, r);
}

int main() {
	fast_io();
//	freopen("input/794F.txt", "r", stdin);

	int n, q;
	int t, l, r;

	cin >> n >> q;
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
	}

	build(1, 1, n);

	while(q--) {
		cin >> t >> l >> r;
		if(t == 1) {
			cin >> from >> to;
			update(1, 1, n, l, r);
		}
		else cout << query(1, 1, n, l, r) << '\n';
	}

	return 0;
}


//#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define mp make_pair

typedef long long ll;
typedef unsigned long long int ull;
typedef long double ld;

typedef pair<int, int> pii;
typedef pair<ll, int> pli;

typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<int> vi;

typedef map<string, int> msi;
typedef map<int, int> mii;
typedef map<int, ll> mill;
typedef map<int, vi> mivi;

const int MAXN = 1e5;

int a[MAXN + 1];
ll tree[10][4 * MAXN];
int lazy[10][4 * MAXN];

int from, to;

void fast_io() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
}

void pushdown(int v, int tl, int tr) {
	for(int i = 0; i < 10; i++) {
		if(lazy[i][v] == -1) continue;
		int pos = lazy[i][v];
		ll at = tree[i][v];

		tree[i][v] = 0;
		tree[pos][v] += at;

		if(tl != tr) {
			int L = (v << 1), R = (L | 1);

			tree[pos][L] += tree[i][L];
			tree[pos][R] += tree[i][R];

			tree[i][L] = 0;
			tree[i][R] = 0;

			lazy[i][L] = pos;
			lazy[i][R] = pos;
		}

		lazy[i][v] = -1;
	}
}

void pushup(int v, int L, int R) {
	for(int i = 0; i < 10; i++)
			tree[i][v] = tree[i][L] + tree[i][R];
}

void build(int v, int l, int r) {
	if(l == r) {
		int tenp = 1, dig = a[l];
		for(int i = 0; dig; i++) {
			tree[dig % 10][v] += tenp;
			tenp *= 10;
			dig /= 10;
		}
	}
	else {
		int mid = (l + r) >> 1;
		int L = (v << 1), R = (L | 1);
		build(L, l, mid);
		build(R, mid + 1, r);
		pushup(v, L, R);
	}
}

void update(int v, int tl, int tr, int l, int r) {
	pushdown(v, tl, tr);
	if(l > tr or r < tl) return;
	if(l <= tl and r >= tr) {
		lazy[from][v] = to;
		pushdown(v, tl, tr);
	}
	else {
		int mid = (tl + tr) >> 1;
		int L = (v << 1), R = (L | 1);
		update(L, tl, mid, l, r);
		update(R, mid + 1, tr, l, r);
		pushup(v, L, R);
	}
}

ll total(int v) {
	ll res = 0;
	for(int i = 0; i < 10; i++)
		res += (1LL * i * tree[i][v]);
	return res;
}

ll query(int v, int tl, int tr, int l, int r) {
	pushdown(v, tl, tr);
	if(l > tr or r < tl) return 0;
	if(l <= tl and r >= tr) return total(v);
	int mid = (tl + tr) >> 1;
	int L = (v << 1), R = (L | 1);
	return query(L, tl, mid, l, r) + query(R, mid + 1, tr, l, r);
}

int main() {
	fast_io();
//	freopen("input/794F.txt", "r", stdin);

	int n, q;
	int t, l, r;

	cin >> n >> q;
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
	}

	memset(lazy, -1, sizeof(lazy));
	build(1, 1, n);

	while(q--) {
		cin >> t >> l >> r;
		if(t == 1) {
			cin >> from >> to;
			update(1, 1, n, l, r);
		}
		else{
			cout << query(1, 1, n, l, r) << '\n';
		}
	}

	return 0;
}


//#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define mp make_pair

typedef long long ll;
typedef unsigned long long int ull;
typedef long double ld;

typedef pair<int, int> pii;
typedef pair<ll, int> pli;

typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<int> vi;

typedef map<string, int> msi;
typedef map<int, int> mii;
typedef map<int, ll> mill;
typedef map<int, vi> mivi;

const int MAXN = 1e5;

int a[MAXN + 1];
ll tree[10][4 * MAXN];
int lazy[10][4 * MAXN];

int from, to;

void fast_io() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
}

void pushdown(int v, int tl, int tr) {
	for(int i = 0; i < 10; i++) {
		if(lazy[i][v] == -1) continue;
		int pos = lazy[i][v];
		ll at = tree[i][v];

		tree[i][v] = 0;
		tree[pos][v] += at;

		if(tl != tr) {
			int L = (v << 1), R = (L | 1);

			ll lsum = tree[i][L];
			ll rsum = tree[i][R];

			tree[i][L] = 0;
			tree[i][R] = 0;

			tree[pos][L] += lsum;
			tree[pos][R] += rsum;

			lazy[i][L] = pos;
			lazy[i][R] = pos;
		}

		lazy[i][v] = -1;
	}
}

void pushup(int v, int L, int R) {
	for(int i = 0; i < 10; i++)
			tree[i][v] = tree[i][L] + tree[i][R];
}

void build(int v, int l, int r) {
	if(l == r) {
		int tenp = 1, dig = a[l];
		for(int i = 0; dig; i++) {
			tree[dig % 10][v] += tenp;
			tenp *= 10;
			dig /= 10;
		}
	}
	else {
		int mid = (l + r) >> 1;
		int L = (v << 1), R = (L | 1);
		build(L, l, mid);
		build(R, mid + 1, r);
		pushup(v, L, R);
	}
}

void update(int v, int tl, int tr, int l, int r) {
	pushdown(v, tl, tr);
	if(l > tr or r < tl) return;
	if(l <= tl and r >= tr) {
		lazy[from][v] = to;
		pushdown(v, tl, tr);
	}
	else {
		int mid = (tl + tr) >> 1;
		int L = (v << 1), R = (L | 1);
		update(L, tl, mid, l, r);
		update(R, mid + 1, tr, l, r);
		pushup(v, L, R);
	}
}

ll total(int v) {
	ll res = 0;
	for(int i = 0; i < 10; i++)
		res += (1LL * i * tree[i][v]);
	return res;
}

ll query(int v, int tl, int tr, int l, int r) {
	pushdown(v, tl, tr);
	if(l > tr or r < tl) return 0;
	if(l <= tl and r >= tr) return total(v);
	int mid = (tl + tr) >> 1;
	int L = (v << 1), R = (L | 1);
	return query(L, tl, mid, l, r) + query(R, mid + 1, tr, l, r);
}

int main() {
	fast_io();
//	freopen("input/794F.txt", "r", stdin);

	int n, q;
	int t, l, r;

	cin >> n >> q;
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
	}

	memset(lazy, -1, sizeof(lazy));
	build(1, 1, n);

	while(q--) {
		cin >> t >> l >> r;
		if(t == 1) {
			cin >> from >> to;
			update(1, 1, n, l, r);
		}
		else{
			cout << query(1, 1, n, l, r) << '\n';
		}
	}

	return 0;
}


//#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define mp make_pair

typedef long long ll;
typedef unsigned long long int ull;
typedef long double ld;

typedef pair<int, int> pii;
typedef pair<ll, int> pli;

typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<int> vi;

typedef map<string, int> msi;
typedef map<int, int> mii;
typedef map<int, ll> mill;
typedef map<int, vi> mivi;

const int MAXN = 1e5;

int a[MAXN + 1];

ll sum[10];
ll tree[10][4 * MAXN];
int lazy[10][4 * MAXN];

int S, T;

void fast_io() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
}

void pushdown(int v, int tl, int tr) {
	if(tl != tr) {
		int L = (v << 1), R = (L | 1);
		for(int i = 0; i <= 9; i++) lazy[i][L] = lazy[lazy[i][L]][v];
		for(int i = 0; i <= 9; i++) lazy[i][R] = lazy[lazy[i][R]][v];
	}

	memset(sum, 0, sizeof(sum));

	for(int i = 0; i <= 9; i++) sum[lazy[i][v]] += tree[i][v];
	for(int i = 0; i <= 9; i++) {
		tree[i][v] = sum[i];
		lazy[i][v] = i;
	}
}

void pushup(int v, int L, int R) {
	for(int i = 0; i <= 9; i++)
		tree[i][v] = tree[i][L] + tree[i][R];
}

void build(int v, int l, int r) {
	for(int i = 0; i <= 9; i++) lazy[i][v] = i;
	if(l == r) {
		int tenp = 1, dig = a[l];
		for(int i = 0; dig; i++) {
			tree[dig % 10][v] += tenp;
			tenp *= 10;
			dig /= 10;
		}
	}
	else {
		int mid = (l + r) >> 1;
		int L = (v << 1), R = (L | 1);
		build(L, l, mid);
		build(R, mid + 1, r);
		pushup(v, L, R);
	}
}

void update(int v, int tl, int tr, int l, int r) {
	pushdown(v, tl, tr);
	if(l > tr or r < tl) return;
	if(l <= tl and r >= tr) {
		lazy[S][v] = T;
		pushdown(v, tl, tr);
	}
	else {
		int mid = (tl + tr) >> 1;
		int L = (v << 1), R = (L | 1);
		update(L, tl, mid, l, r);
		update(R, mid + 1, tr, l, r);
		pushup(v, L, R);
	}
}

ll total(int v) {
	ll res = 0;
	for(int i = 0; i <= 9; i++)
		res += (1LL * i * tree[i][v]);
	return res;
}

ll query(int v, int tl, int tr, int l, int r) {
	pushdown(v, tl, tr);
	if(l > tr or r < tl) return 0;
	if(l <= tl and r >= tr) return total(v);
	int mid = (tl + tr) >> 1;
	int L = (v << 1), R = (L | 1);
	return query(L, tl, mid, l, r) + query(R, mid + 1, tr, l, r);
}

int main() {
	fast_io();
//	freopen("input/794F.txt", "r", stdin);

	int n, q;
	int t, l, r;

	cin >> n >> q;
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
	}

	build(1, 1, n);

	while(q--) {
		cin >> t >> l >> r;
		if(t == 1) {
			cin >> S >> T;
			update(1, 1, n, l, r);
		}
		else cout << query(1, 1, n, l, r) << '\n';
	}

	return 0;
}


//#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define mp make_pair

typedef long long ll;
typedef unsigned long long int ull;
typedef long double ld;

typedef pair<int, int> pii;
typedef pair<ll, int> pli;

typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<int> vi;

typedef map<string, int> msi;
typedef map<int, int> mii;
typedef map<int, ll> mill;
typedef map<int, vi> mivi;

const int MAXN = 1e5;

int a[MAXN + 1];

ll sum[10];
ll tree[10][4 * MAXN];
int lazy[10][4 * MAXN];

int from, to;

void fast_io() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
}

void pushdown(int v, int tl, int tr) {
	if(tl != tr) {
		int L = (v << 1), R = (L | 1);
		for(int i = 0; i <= 9; i++) lazy[i][L] = lazy[lazy[i][L]][v];
		for(int i = 0; i <= 9; i++) lazy[i][R] = lazy[lazy[i][R]][v];
	}

	memset(sum, 0, sizeof(sum));

	for(int i = 0; i <= 9; i++) sum[lazy[i][v]] += tree[i][v];
	for(int i = 0; i <= 9; i++) {
		tree[i][v] = sum[i];
		lazy[i][v] = i;
	}
}

void pushup(int v, int L, int R) {
	for(int i = 0; i < 10; i++)
			tree[i][v] = tree[i][L] + tree[i][R];
}

void build(int v, int l, int r) {
	for(int i = 0; i <= 9; i++) lazy[i][v] = i;
	if(l == r) {
		int tenp = 1, dig = a[l];
		for(int i = 0; dig; i++) {
			tree[dig % 10][v] += tenp;
			tenp *= 10;
			dig /= 10;
		}
	}
	else {
		int mid = (l + r) >> 1;
		int L = (v << 1), R = (L | 1);
		build(L, l, mid);
		build(R, mid + 1, r);
		pushup(v, L, R);
	}
}

void update(int v, int tl, int tr, int l, int r) {
	pushdown(v, tl, tr);
	if(l > tr or r < tl) return;
	if(l <= tl and r >= tr) {
		lazy[from][v] = to;
		pushdown(v, tl, tr);
	}
	else {
		int mid = (tl + tr) >> 1;
		int L = (v << 1), R = (L | 1);
		update(L, tl, mid, l, r);
		update(R, mid + 1, tr, l, r);
		pushup(v, L, R);
	}
}

ll total(int v) {
	ll res = 0;
	for(int i = 0; i <= 9; i++)
		res += (1LL * i * tree[i][v]);
	return res;
}

ll query(int v, int tl, int tr, int l, int r) {
	pushdown(v, tl, tr);
	if(l > tr or r < tl) return 0;
	if(l <= tl and r >= tr) return total(v);
	int mid = (tl + tr) >> 1;
	int L = (v << 1), R = (L | 1);
	return query(L, tl, mid, l, r) + query(R, mid + 1, tr, l, r);
}

int main() {
	fast_io();
//	freopen("input/794F.txt", "r", stdin);

	int n, q;
	int t, l, r;

	cin >> n >> q;
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
	}

	build(1, 1, n);

	while(q--) {
		cin >> t >> l >> r;
		if(t == 1) {
			cin >> from >> to;
			update(1, 1, n, l, r);
		}
		else cout << query(1, 1, n, l, r) << '\n';
	}

	return 0;
}


//#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define mp make_pair

typedef long long ll;
typedef unsigned long long int ull;
typedef long double ld;

typedef pair<int, int> pii;
typedef pair<ll, int> pli;

typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<int> vi;

typedef map<string, int> msi;
typedef map<int, int> mii;
typedef map<int, ll> mill;
typedef map<int, vi> mivi;

const int MAXN = 1e5;

int a[MAXN + 1];

ll sum[10];
ll tree[10][4 * MAXN];
int lazy[10][4 * MAXN];

int s, t;

void fast_io() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
}

void pushdown(int v, int tl, int tr) {
	if(tl != tr) {
		int L = (v << 1), R = (L | 1);
		for(int i = 0; i <= 9; i++) lazy[i][L] = lazy[lazy[i][L]][v];
		for(int i = 0; i <= 9; i++) lazy[i][R] = lazy[lazy[i][R]][v];
	}

	memset(sum, 0, sizeof(sum));

	for(int i = 0; i <= 9; i++) sum[lazy[i][v]] += tree[i][v];
	for(int i = 0; i <= 9; i++) {
		tree[i][v] = sum[i];
		lazy[i][v] = i;
	}
}

void pushup(int v, int L, int R) {
	for(int i = 0; i < 10; i++)
		tree[i][v] = tree[i][L] + tree[i][R];
}

void build(int v, int l, int r) {
	for(int i = 0; i <= 9; i++) lazy[i][v] = i;
	if(l == r) {
		int tenp = 1, dig = a[l];
		for(int i = 0; dig; i++) {
			tree[dig % 10][v] += tenp;
			tenp *= 10;
			dig /= 10;
		}
	}
	else {
		int mid = (l + r) >> 1;
		int L = (v << 1), R = (L | 1);
		build(L, l, mid);
		build(R, mid + 1, r);
		pushup(v, L, R);
	}
}

void update(int v, int tl, int tr, int l, int r) {
	pushdown(v, tl, tr);
	if(l > tr or r < tl) return;
	if(l <= tl and r >= tr) {
		lazy[s][v] = t;
		pushdown(v, tl, tr);
	}
	else {
		int mid = (tl + tr) >> 1;
		int L = (v << 1), R = (L | 1);
		update(L, tl, mid, l, r);
		update(R, mid + 1, tr, l, r);
		pushup(v, L, R);
	}
}

ll total(int v) {
	ll res = 0;
	for(int i = 0; i <= 9; i++)
		res += (1LL * i * tree[i][v]);
	return res;
}

ll query(int v, int tl, int tr, int l, int r) {
	pushdown(v, tl, tr);
	if(l > tr or r < tl) return 0;
	if(l <= tl and r >= tr) return total(v);
	int mid = (tl + tr) >> 1;
	int L = (v << 1), R = (L | 1);
	return query(L, tl, mid, l, r) + query(R, mid + 1, tr, l, r);
}

int main() {
	fast_io();
//	freopen("input/794F.txt", "r", stdin);

	int n, q;
	int t, l, r;

	cin >> n >> q;
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
	}

	build(1, 1, n);

	while(q--) {
		cin >> t >> l >> r;
		if(t == 1) {
			cin >> s >> t;
			update(1, 1, n, l, r);
		}
		else cout << query(1, 1, n, l, r) << '\n';
	}

	return 0;
}


//#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define mp make_pair

typedef long long ll;
typedef unsigned long long int ull;
typedef long double ld;

typedef pair<int, int> pii;
typedef pair<ll, int> pli;

typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<int> vi;

typedef map<string, int> msi;
typedef map<int, int> mii;
typedef map<int, ll> mill;
typedef map<int, vi> mivi;

const int MAXN = 1e5;

int a[MAXN + 1];

ll tree[10][4 * MAXN];
int lazy[10][4 * MAXN];
int cpylazy[10];

int from, to;

void fast_io() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
}

void clean(int i, int v, bool o) {
	if(!lazy[i][v]) return;

	int pos = lazy[i][v];
	ll at = tree[i][v];

	tree[i][v] = 0;
	tree[pos][v] += at;

	if(!o) cpylazy[i] = lazy[i][v];
	lazy[i][v] = 0;
}

void pushdown(int v, int tl, int tr, bool up) {
	bool ok = false;
	for(int i = 0; i < 10; i++) {
		if(lazy[i][v]) ok |= 1;
	}
	if(!ok) return;

	memset(cpylazy, 0, sizeof(cpylazy));

	for(int i = 0; i < 10; i++)
		clean(i, v, 0);

	if(tl != tr) {
		int L = (v << 1), R = (L | 1);
		for(int i = 0; i < 10; i++) clean(i, L, 1);
		for(int i = 0; i < 10; i++) clean(i, R, 1);
		for(int i = 0; i < 10; i++) lazy[i][L] = cpylazy[i];
		for(int i = 0; i < 10; i++) lazy[i][R] = cpylazy[i];
	}
}

void pushup(int v, int L, int R) {
	for(int i = 0; i < 10; i++)
			tree[i][v] = tree[i][L] + tree[i][R];
}

void build(int v, int l, int r) {
	if(l == r) {
		int tenp = 1, dig = a[l];
		for(int i = 0; dig; i++) {
			tree[dig % 10][v] += tenp;
			tenp *= 10;
			dig /= 10;
		}
	}
	else {
		int mid = (l + r) >> 1;
		int L = (v << 1), R = (L | 1);
		build(L, l, mid);
		build(R, mid + 1, r);
		pushup(v, L, R);
	}
}

void update(int v, int tl, int tr, int l, int r) {
	pushdown(v, tl, tr, 1);
	if(l > tr or r < tl) return;
	if(l <= tl and r >= tr) {
		lazy[from][v] = to;
		pushdown(v, tl, tr, 1);
	}
	else {
		int mid = (tl + tr) >> 1;
		int L = (v << 1), R = (L | 1);
		update(L, tl, mid, l, r);
		update(R, mid + 1, tr, l, r);
		pushup(v, L, R);
	}
}

ll total(int v) {
	ll res = 0;
	for(int i = 0; i < 10; i++)
		res += (1LL * i * tree[i][v]);
	return res;
}

ll query(int v, int tl, int tr, int l, int r) {
	pushdown(v, tl, tr, 0);
	if(l > tr or r < tl) return 0;
	if(l <= tl and r >= tr) return total(v);
	int mid = (tl + tr) >> 1;
	int L = (v << 1), R = (L | 1);
	return query(L, tl, mid, l, r) + query(R, mid + 1, tr, l, r);
}

int main() {
	fast_io();
//	freopen("input/794F.txt", "r", stdin);

	int n, q;
	int t, l, r;

	cin >> n >> q;
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
	}

	build(1, 1, n);

	while(q--) {
		cin >> t >> l >> r;
		if(t == 1) {
			cin >> from >> to;
			update(1, 1, n, l, r);
		}
		else cout << query(1, 1, n, l, r) << '\n';
	}

	return 0;
}


//#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define mp make_pair

typedef long long ll;
typedef unsigned long long int ull;
typedef long double ld;

typedef pair<int, int> pii;
typedef pair<ll, int> pli;

typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<int> vi;

typedef map<string, int> msi;
typedef map<int, int> mii;
typedef map<int, ll> mill;
typedef map<int, vi> mivi;

const int MAXN = 1e5;

int a[MAXN + 1];

ll tree[10][4 * MAXN];
int lazy[10][4 * MAXN];

int from, to;

void fast_io() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
}

void clean(int i, int v, bool o) {
	int pos = lazy[i][v];
	ll at = tree[i][v];

	tree[i][v] = 0;
	tree[pos][v] += at;

	lazy[i][v] = i;
}

void pushdown(int v, int tl, int tr, bool up) {
	if(tl != tr) {
		int L = (v << 1), R = (L | 1);
		for(int i = 0; i <= 9; i++) lazy[i][L] = lazy[lazy[i][L]][v];
		for(int i = 0; i <= 9; i++) lazy[i][R] = lazy[lazy[i][R]][v];
	}
	for(int i = 0; i <= 9; i++) clean(i, v, 0);
}

void pushup(int v, int L, int R) {
	for(int i = 0; i < 10; i++)
			tree[i][v] = tree[i][L] + tree[i][R];
}

void build(int v, int l, int r) {
	for(int i = 0; i <= 9; i++) lazy[i][v] = i;
	if(l == r) {
		int tenp = 1, dig = a[l];
		for(int i = 0; dig; i++) {
			tree[dig % 10][v] += tenp;
			tenp *= 10;
			dig /= 10;
		}
	}
	else {
		int mid = (l + r) >> 1;
		int L = (v << 1), R = (L | 1);
		build(L, l, mid);
		build(R, mid + 1, r);
		pushup(v, L, R);
	}
}

void update(int v, int tl, int tr, int l, int r) {
	pushdown(v, tl, tr, 1);
	if(l > tr or r < tl) return;
	if(l <= tl and r >= tr) {
		lazy[from][v] = to;
		pushdown(v, tl, tr, 1);
	}
	else {
		int mid = (tl + tr) >> 1;
		int L = (v << 1), R = (L | 1);
		update(L, tl, mid, l, r);
		update(R, mid + 1, tr, l, r);
		pushup(v, L, R);
	}
}

ll total(int v) {
	ll res = 0;
	for(int i = 0; i < 10; i++)
		res += (1LL * i * tree[i][v]);
	return res;
}

ll query(int v, int tl, int tr, int l, int r) {
	pushdown(v, tl, tr, 0);
	if(l > tr or r < tl) return 0;
	if(l <= tl and r >= tr) return total(v);
	int mid = (tl + tr) >> 1;
	int L = (v << 1), R = (L | 1);
	return query(L, tl, mid, l, r) + query(R, mid + 1, tr, l, r);
}

int main() {
	fast_io();
//	freopen("input/794F.txt", "r", stdin);

	int n, q;
	int t, l, r;

	cin >> n >> q;
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
	}

	build(1, 1, n);

	while(q--) {
		cin >> t >> l >> r;
		if(t == 1) {
			cin >> from >> to;
			update(1, 1, n, l, r);
		}
		else cout << query(1, 1, n, l, r) << '\n';
	}

	return 0;
}


//#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define mp make_pair

typedef long long ll;
typedef unsigned long long int ull;
typedef long double ld;

typedef pair<int, int> pii;
typedef pair<ll, int> pli;

typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<int> vi;

typedef map<string, int> msi;
typedef map<int, int> mii;
typedef map<int, ll> mill;
typedef map<int, vi> mivi;

const int MAXN = 1e5;

int a[MAXN + 1];

ll sum[10];
ll tree[10][4 * MAXN + 1];
int lazy[10][4 * MAXN + 1];

int from, to;

void fast_io() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
}

void clean(int i, int v) {
	int pos = lazy[i][v];
	ll at = tree[i][v];

	tree[i][v] = 0;
	tree[pos][v] += at;

	lazy[i][v] = i;
}

void pushdown(int v, int tl, int tr) {
	if(tl != tr) {
		int L = (v << 1), R = (L | 1);
		for(int i = 0; i <= 9; i++) lazy[i][L] = lazy[lazy[i][L]][v];
		for(int i = 0; i <= 9; i++) lazy[i][R] = lazy[lazy[i][R]][v];
	}

	memset(sum, 0, sizeof(sum));

	for(int i = 0; i <= 9; i++) sum[lazy[i][v]] += tree[i][v];
	for(int i = 0; i <= 9; i++) {
		tree[i][v] = sum[i];
		lazy[i][v] = i;
	}
}

void pushup(int v, int L, int R) {
	for(int i = 0; i < 10; i++)
			tree[i][v] = tree[i][L] + tree[i][R];
}

void build(int v, int l, int r) {
	for(int i = 0; i <= 9; i++) lazy[i][v] = i;
	if(l == r) {
		int tenp = 1, dig = a[l];
		for(int i = 0; dig; i++) {
			tree[dig % 10][v] += tenp;
			tenp *= 10;
			dig /= 10;
		}
	}
	else {
		int mid = (l + r) >> 1;
		int L = (v << 1), R = (L | 1);
		build(L, l, mid);
		build(R, mid + 1, r);
		pushup(v, L, R);
	}
}

void update(int v, int tl, int tr, int l, int r) {
	pushdown(v, tl, tr);
	if(l > tr or r < tl) return;
	if(l <= tl and r >= tr) {
		lazy[from][v] = to;
		pushdown(v, tl, tr);
	}
	else {
		int mid = (tl + tr) >> 1;
		int L = (v << 1), R = (L | 1);
		update(L, tl, mid, l, r);
		update(R, mid + 1, tr, l, r);
		pushup(v, L, R);
	}
}

ll total(int v) {
	ll res = 0;
	for(int i = 0; i <= 9; i++)
		res += (1LL * i * tree[i][v]);
	return res;
}

ll query(int v, int tl, int tr, int l, int r) {
	pushdown(v, tl, tr);
	if(l > tr or r < tl) return 0;
	if(l <= tl and r >= tr) return total(v);
	int mid = (tl + tr) >> 1;
	int L = (v << 1), R = (L | 1);
	return query(L, tl, mid, l, r) + query(R, mid + 1, tr, l, r);
}

int main() {
	fast_io();
//	freopen("input/794F.txt", "r", stdin);

	int n, q;
	int t, l, r;

	cin >> n >> q;
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
	}

	build(1, 1, n);

	while(q--) {
		cin >> t >> l >> r;
		if(t == 1) {
			cin >> from >> to;
			update(1, 1, n, l, r);
		}
		else cout << query(1, 1, n, l, r) << '\n';
	}

	return 0;
}


//#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define mp make_pair

typedef long long ll;
typedef unsigned long long int ull;
typedef long double ld;

typedef pair<int, int> pii;
typedef pair<ll, int> pli;

typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<int> vi;

typedef map<string, int> msi;
typedef map<int, int> mii;
typedef map<int, ll> mill;
typedef map<int, vi> mivi;

const int MAXN = 1e5;

int a[MAXN + 1];
ll tree[10][4 * MAXN];
int lazy[10][4 * MAXN];

int from, to;

void fast_io() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
}

void pushdown(int v, int tl, int tr) {
	for(int i = 0; i < 10; i++) {
		if(lazy[i][v] == -1) continue;
		int pos = lazy[i][v];
		ll at = tree[i][v];

		tree[i][v] = 0;
		tree[pos][v] += at;

		if(tl != tr) {
			int L = (v << 1), R = (L | 1);
			lazy[i][L] = pos;
			lazy[i][R] = pos;
		}
		lazy[i][v] = -1;
	}
}

void build(int v, int l, int r) {
	if(l == r) {
		int tenp = 1, dig = a[l];
		for(int i = 0; dig; i++) {
			tree[dig % 10][v] += tenp;
			tenp *= 10;
			dig /= 10;
		}
	}
	else {
		int mid = (l + r) >> 1;
		int L = (v << 1), R = (L | 1);
		build(L, l, mid);
		build(R, mid + 1, r);
		for(int i = 0; i < 10; i++)
			tree[i][v] = tree[i][L] + tree[i][R];
	}
}

void update(int v, int tl, int tr, int l, int r) {
	pushdown(v, tl, tr);
	if(l > tr or r < tl) return;
	if(l <= tl and r >= tr) {
		lazy[from][v] = to;
		pushdown(v, tl, tr);
	}
	else {
		int mid = (tl + tr) >> 1;
		int L = (v << 1), R = (L | 1);
		update(L, tl, mid, l, r);
		update(R, mid + 1, tr, l, r);
		for(int i = 0; i < 10; i++)
			tree[i][v] = tree[i][L] + tree[i][R];
	}
}

ll total(int v) {
	ll res = 0;
	for(int i = 0; i < 10; i++)
		res += (1LL * i * tree[i][v]);
	return res;
}

ll query(int v, int tl, int tr, int l, int r) {
	pushdown(v, tl, tr);
	if(l > tr or r < tl) return 0;
	if(l <= tl and r >= tr) return total(v);
	int mid = (tl + tr) >> 1;
	int L = (v << 1), R = (L | 1);
	return query(L, tl, mid, l, r) + query(R, mid + 1, tr, l, r);
}

int main() {
	fast_io();
//	freopen("input/794F.txt", "r", stdin);

	int n, q;
	int t, l, r;

	cin >> n >> q;
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
	}

	memset(lazy, -1, sizeof(lazy));
	build(1, 1, n);

	while(q--) {
		cin >> t >> l >> r;
		if(t == 1) {
			cin >> from >> to;
			update(1, 1, n, l, r);
		}
		else cout << query(1, 1, n, l, r) << '\n';
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
bool Finish_read;
template<class T>inline void read(T &x){Finish_read=0;x=0;int f=1;char ch=getchar();while(!isdigit(ch)){if(ch=='-')f=-1;if(ch==EOF)return;ch=getchar();}while(isdigit(ch))x=x*10+ch-'0',ch=getchar();x*=f;Finish_read=1;}
template<class T>inline void print(T x){if(x/10!=0)print(x/10);putchar(x%10+'0');}
template<class T>inline void writeln(T x){if(x<0)putchar('-');x=abs(x);print(x);putchar('\n');}
template<class T>inline void write(T x){if(x<0)putchar('-');x=abs(x);print(x);}
/*================Header Template==============*/
#define PAUSE printf("Press Enter key to continue..."); fgetc(stdin);
const int N=1e5+500;
const int M=11;
int n,m;
int a[N];
/*==================Define Area================*/
namespace SegmentTree {
	struct node {
		int l,r;
		ll sum[10];
		int to[10];
		void Reset() {
			memset(sum,0,sizeof sum);
		}
		void Init() {
			for(int i=0;i<=9;i++) to[i]=i,sum[i]=0;
		}
		void Print() {
			printf("[%d,%d] --> ",l,r);
			for(int i=0;i<=9;i++) printf("%lld ",sum[i]);
			puts("");
		}
	}t[N];
	int tmp[10];
	#define ls(o) o<<1
	#define rs(o) o<<1|1
	void Update(int o) {
		t[o].Reset();
		for(int i=0;i<=9;i++) t[o].sum[t[ls(o)].to[i]]+=t[ls(o)].sum[i];
		for(int i=0;i<=9;i++) t[o].sum[t[rs(o)].to[i]]+=t[rs(o)].sum[i];
	}
	void Pushdown(int o) {
		for(int i=0;i<=9;i++) t[ls(o)].to[i]=t[o].to[t[ls(o)].to[i]];
		for(int i=0;i<=9;i++) t[rs(o)].to[i]=t[o].to[t[rs(o)].to[i]];
		memset(tmp,0,sizeof tmp);
		for(int i=0;i<=9;i++) tmp[t[o].to[i]]+=t[o].sum[i];
		for(int i=0;i<=9;i++) t[o].sum[i]=tmp[i];
		for(int i=0;i<=9;i++) t[o].to[i]=i;
	}
	void Build(int o,int l,int r) {
		t[o].l=l;t[o].r=r;t[o].Init();
		if(l==r) {
			int p=a[l],tmp=1;
			while(p) {
				int num=p%10;p/=10;
				t[o].sum[num]+=tmp;tmp*=10;
			}
			return ;
		}
		int mid=(l+r)>>1;
		Build(ls(o),l,mid);
		Build(rs(o),mid+1,r);
		for(int i=0;i<=9;i++) t[o].sum[i]=t[ls(o)].sum[i]+t[rs(o)].sum[i];
		Update(o);
	}
	void Modify(int o,int l,int r,int x,int y) {
		if(t[o].l>=l&&t[o].r<=r) {
			for(int i=0;i<=9;i++) if(t[o].to[i]==x) t[o].to[i]=y;
			return ;
		}
		Pushdown(o);
		int mid=(t[o].l+t[o].r)>>1;
		if(mid>=l) Modify(ls(o),l,r,x,y);
		if(mid<r) Modify(rs(o),l,r,x,y);
		Update(o);
	}
	ll Query(int o,int l,int r) {
		if(t[o].l>=l&&t[o].r<=r) {
			ll res=0;
			for(int i=1;i<=9;i++) res+=(ll)t[o].sum[i]*t[o].to[i];
			return res;
		}
		Pushdown(o);
		int mid=(t[o].l+t[o].r)>>1;
		ll res=0;
		if(mid>=l) res+=Query(ls(o),l,r);
		if(mid<r) res+=Query(rs(o),l,r);
		return res;
	}
	void Debug(int o) {
		if(!o) return ;
		if(!t[o].l) return ;
		Pushdown(o);
		Debug(ls(o));
		t[o].Print();
		Debug(rs(o));
		return ;
	}
}
using namespace SegmentTree;

int main() {
	read(n);read(m);
	for(int i=1;i<=n;i++) read(a[i]);
	Build(1,1,n);
	// puts("GG");
	while(m--) {
		int opt;
		read(opt);
		if(opt==1) {
			int l,r,x,y;
			read(l);read(r);read(x);read(y);
			Modify(1,l,r,x,y);
		}
		else {
			int l,r;
			read(l);read(r);
			printf("%lld\n",Query(1,l,r));
		}
		// puts("Debug :");
		// Debug(1);
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
bool Finish_read;
template<class T>inline void read(T &x){Finish_read=0;x=0;int f=1;char ch=getchar();while(!isdigit(ch)){if(ch=='-')f=-1;if(ch==EOF)return;ch=getchar();}while(isdigit(ch))x=x*10+ch-'0',ch=getchar();x*=f;Finish_read=1;}
template<class T>inline void print(T x){if(x/10!=0)print(x/10);putchar(x%10+'0');}
template<class T>inline void writeln(T x){if(x<0)putchar('-');x=abs(x);print(x);putchar('\n');}
template<class T>inline void write(T x){if(x<0)putchar('-');x=abs(x);print(x);}
/*================Header Template==============*/
#define PAUSE printf("Press Enter key to continue..."); fgetc(stdin);
#define int ll
const int N=1e5+500;
const int M=11;
int n,m;
int a[N];
/*==================Define Area================*/
namespace SegmentTree {
	struct node {
		int l,r;
		ll sum[10];
		int to[10];
		void Reset() {
			memset(sum,0,sizeof sum);
		}
		void Init() {
			for(int i=0;i<=9;i++) to[i]=i,sum[i]=0;
		}
		// void Print() {
		// 	printf("[%d,%d] --> ",l,r);
		// 	for(int i=0;i<=9;i++) printf("%lld ",sum[i]);
		// 	puts("");
		// }
	}t[N<<2];
	ll tmp[10];
	#define ls(o) o<<1
	#define rs(o) o<<1|1
	void Update(int o) {
		t[o].Reset();
		for(int i=0;i<=9;i++) t[o].sum[t[ls(o)].to[i]]+=t[ls(o)].sum[i];
		for(int i=0;i<=9;i++) t[o].sum[t[rs(o)].to[i]]+=t[rs(o)].sum[i];
	}
	void Pushdown(int o) {
		for(int i=0;i<=9;i++) t[ls(o)].to[i]=t[o].to[t[ls(o)].to[i]];
		for(int i=0;i<=9;i++) t[rs(o)].to[i]=t[o].to[t[rs(o)].to[i]];
		memset(tmp,0,sizeof tmp);
		for(int i=0;i<=9;i++) tmp[t[o].to[i]]+=t[o].sum[i];
		for(int i=0;i<=9;i++) t[o].sum[i]=tmp[i];
		for(int i=0;i<=9;i++) t[o].to[i]=i;
	}
	void Build(int o,int l,int r) {
		t[o].l=l;t[o].r=r;t[o].Init();
		if(l==r) {
			int p=a[l],tmp=1;
			while(p) {
				int num=p%10;p/=10;
				t[o].sum[num]+=tmp;tmp*=10;
			}
			return ;
		}
		int mid=(l+r)>>1;
		Build(ls(o),l,mid);
		Build(rs(o),mid+1,r);
		for(int i=0;i<=9;i++) t[o].sum[i]=t[ls(o)].sum[i]+t[rs(o)].sum[i];
		Update(o);
	}
	void Modify(int o,int l,int r,int x,int y) {
		if(t[o].l>=l&&t[o].r<=r) {
			for(int i=0;i<=9;i++) if(t[o].to[i]==x) t[o].to[i]=y;
			return ;
		}
		Pushdown(o);
		int mid=(t[o].l+t[o].r)>>1;
		if(mid>=l) Modify(ls(o),l,r,x,y);
		if(mid<r) Modify(rs(o),l,r,x,y);
		Update(o);
	}
	ll Query(int o,int l,int r) {
		if(t[o].l>=l&&t[o].r<=r) {
			ll res=0;
			for(int i=1;i<=9;i++) res+=(ll)t[o].sum[i]*t[o].to[i];
			return res;
		}
		Pushdown(o);
		int mid=(t[o].l+t[o].r)>>1;
		ll res=0;
		if(mid>=l) res+=Query(ls(o),l,r);
		if(mid<r) res+=Query(rs(o),l,r);
		return res;
	}
	// void Debug(int o) {
	// 	if(!o) return ;
	// 	if(!t[o].l) return ;
	// 	Pushdown(o);
	// 	Debug(ls(o));
	// 	t[o].Print();
	// 	Debug(rs(o));
	// 	return ;
	// }
}
using namespace SegmentTree;

signed main() {
	read(n);read(m);
	for(int i=1;i<=n;i++) read(a[i]);
	Build(1,1,n);
	// puts("GG");
	while(m--) {
		int opt;
		read(opt);
		if(opt==1) {
			int l,r,x,y;
			read(l);read(r);read(x);read(y);
			Modify(1,l,r,x,y);
		}
		else {
			int l,r;
			read(l);read(r);
			printf("%lld\n",Query(1,l,r));
		}
		// puts("Debug :");
		// Debug(1);
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
bool Finish_read;
template<class T>inline void read(T &x){Finish_read=0;x=0;int f=1;char ch=getchar();while(!isdigit(ch)){if(ch=='-')f=-1;if(ch==EOF)return;ch=getchar();}while(isdigit(ch))x=x*10+ch-'0',ch=getchar();x*=f;Finish_read=1;}
template<class T>inline void print(T x){if(x/10!=0)print(x/10);putchar(x%10+'0');}
template<class T>inline void writeln(T x){if(x<0)putchar('-');x=abs(x);print(x);putchar('\n');}
template<class T>inline void write(T x){if(x<0)putchar('-');x=abs(x);print(x);}
/*================Header Template==============*/
#define PAUSE printf("Press Enter key to continue..."); fgetc(stdin);
const int N=1e5+500;
const int M=11;
int n,m;
int a[N];
/*==================Define Area================*/
namespace SegmentTree {
	struct node {
		int l,r;
		ll sum[10];
		int to[10];
		void Reset() {
			memset(sum,0,sizeof sum);
		}
		void Init() {
			for(int i=0;i<=9;i++) to[i]=i,sum[i]=0;
		}
		void Print() {
			printf("[%d,%d] --> ",l,r);
			for(int i=0;i<=9;i++) printf("%lld ",sum[i]);
			puts("");
		}
	}t[N<<2];
	int tmp[10];
	#define ls(o) o<<1
	#define rs(o) o<<1|1
	void Update(int o) {
		t[o].Reset();
		for(int i=0;i<=9;i++) t[o].sum[t[ls(o)].to[i]]+=t[ls(o)].sum[i];
		for(int i=0;i<=9;i++) t[o].sum[t[rs(o)].to[i]]+=t[rs(o)].sum[i];
	}
	void Pushdown(int o) {
		for(int i=0;i<=9;i++) t[ls(o)].to[i]=t[o].to[t[ls(o)].to[i]];
		for(int i=0;i<=9;i++) t[rs(o)].to[i]=t[o].to[t[rs(o)].to[i]];
		memset(tmp,0,sizeof tmp);
		for(int i=0;i<=9;i++) tmp[t[o].to[i]]+=t[o].sum[i];
		for(int i=0;i<=9;i++) t[o].sum[i]=tmp[i];
		for(int i=0;i<=9;i++) t[o].to[i]=i;
	}
	void Build(int o,int l,int r) {
		t[o].l=l;t[o].r=r;t[o].Init();
		if(l==r) {
			int p=a[l],tmp=1;
			while(p) {
				int num=p%10;p/=10;
				t[o].sum[num]+=tmp;tmp*=10;
			}
			return ;
		}
		int mid=(l+r)>>1;
		Build(ls(o),l,mid);
		Build(rs(o),mid+1,r);
		for(int i=0;i<=9;i++) t[o].sum[i]=t[ls(o)].sum[i]+t[rs(o)].sum[i];
		Update(o);
	}
	void Modify(int o,int l,int r,int x,int y) {
		if(t[o].l>=l&&t[o].r<=r) {
			for(int i=0;i<=9;i++) if(t[o].to[i]==x) t[o].to[i]=y;
			return ;
		}
		Pushdown(o);
		int mid=(t[o].l+t[o].r)>>1;
		if(mid>=l) Modify(ls(o),l,r,x,y);
		if(mid<r) Modify(rs(o),l,r,x,y);
		Update(o);
	}
	ll Query(int o,int l,int r) {
		if(t[o].l>=l&&t[o].r<=r) {
			ll res=0;
			for(int i=1;i<=9;i++) res+=(ll)t[o].sum[i]*t[o].to[i];
			return res;
		}
		Pushdown(o);
		int mid=(t[o].l+t[o].r)>>1;
		ll res=0;
		if(mid>=l) res+=Query(ls(o),l,r);
		if(mid<r) res+=Query(rs(o),l,r);
		return res;
	}
	void Debug(int o) {
		if(!o) return ;
		if(!t[o].l) return ;
		Pushdown(o);
		Debug(ls(o));
		t[o].Print();
		Debug(rs(o));
		return ;
	}
}
using namespace SegmentTree;

int main() {
	read(n);read(m);
	for(int i=1;i<=n;i++) read(a[i]);
	Build(1,1,n);
	// puts("GG");
	while(m--) {
		int opt;
		read(opt);
		if(opt==1) {
			int l,r,x,y;
			read(l);read(r);read(x);read(y);
			Modify(1,l,r,x,y);
		}
		else {
			int l,r;
			read(l);read(r);
			printf("%lld\n",Query(1,l,r));
		}
		// puts("Debug :");
		// Debug(1);
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
bool Finish_read;
template<class T>inline void read(T &x){Finish_read=0;x=0;int f=1;char ch=getchar();while(!isdigit(ch)){if(ch=='-')f=-1;if(ch==EOF)return;ch=getchar();}while(isdigit(ch))x=x*10+ch-'0',ch=getchar();x*=f;Finish_read=1;}
template<class T>inline void print(T x){if(x/10!=0)print(x/10);putchar(x%10+'0');}
template<class T>inline void writeln(T x){if(x<0)putchar('-');x=abs(x);print(x);putchar('\n');}
template<class T>inline void write(T x){if(x<0)putchar('-');x=abs(x);print(x);}
/*================Header Template==============*/
#define PAUSE printf("Press Enter key to continue..."); fgetc(stdin);
const int N=1e5+500;
const int M=11;
int n,m;
int a[N];
/*==================Define Area================*/
namespace SegmentTree {
	struct node {
		int l,r;
		ll sum[10];
		int to[10];
		void Reset() {
			memset(sum,0,sizeof sum);
		}
		void Init() {
			for(int i=0;i<=9;i++) to[i]=i,sum[i]=0;
		}
		void Print() {
			printf("[%d,%d] --> ",l,r);
			for(int i=0;i<=9;i++) printf("%lld ",sum[i]);
			puts("");
		}
	}t[N<<2];
	ll tmp[10];
	#define ls(o) o<<1
	#define rs(o) o<<1|1
	void Update(int o) {
		t[o].Reset();
		for(int i=0;i<=9;i++) t[o].sum[t[ls(o)].to[i]]+=t[ls(o)].sum[i];
		for(int i=0;i<=9;i++) t[o].sum[t[rs(o)].to[i]]+=t[rs(o)].sum[i];
	}
	void Pushdown(int o) {
		for(int i=0;i<=9;i++) t[ls(o)].to[i]=t[o].to[t[ls(o)].to[i]];
		for(int i=0;i<=9;i++) t[rs(o)].to[i]=t[o].to[t[rs(o)].to[i]];
		memset(tmp,0,sizeof tmp);
		for(int i=0;i<=9;i++) tmp[t[o].to[i]]+=t[o].sum[i];
		for(int i=0;i<=9;i++) t[o].sum[i]=tmp[i];
		for(int i=0;i<=9;i++) t[o].to[i]=i;
	}
	void Build(int o,int l,int r) {
		t[o].l=l;t[o].r=r;t[o].Init();
		if(l==r) {
			int p=a[l],tmp=1;
			while(p) {
				int num=p%10;p/=10;
				t[o].sum[num]+=tmp;tmp*=10;
			}
			return ;
		}
		int mid=(l+r)>>1;
		Build(ls(o),l,mid);
		Build(rs(o),mid+1,r);
		for(int i=0;i<=9;i++) t[o].sum[i]=t[ls(o)].sum[i]+t[rs(o)].sum[i];
		Update(o);
	}
	void Modify(int o,int l,int r,int x,int y) {
		if(t[o].l>=l&&t[o].r<=r) {
			for(int i=0;i<=9;i++) if(t[o].to[i]==x) t[o].to[i]=y;
			return ;
		}
		Pushdown(o);
		int mid=(t[o].l+t[o].r)>>1;
		if(mid>=l) Modify(ls(o),l,r,x,y);
		if(mid<r) Modify(rs(o),l,r,x,y);
		Update(o);
	}
	ll Query(int o,int l,int r) {
		if(t[o].l>=l&&t[o].r<=r) {
			ll res=0;
			for(int i=1;i<=9;i++) res+=(ll)t[o].sum[i]*t[o].to[i];
			return res;
		}
		Pushdown(o);
		int mid=(t[o].l+t[o].r)>>1;
		ll res=0;
		if(mid>=l) res+=Query(ls(o),l,r);
		if(mid<r) res+=Query(rs(o),l,r);
		return res;
	}
	void Debug(int o) {
		if(!o) return ;
		if(!t[o].l) return ;
		Pushdown(o);
		Debug(ls(o));
		t[o].Print();
		Debug(rs(o));
		return ;
	}
}
using namespace SegmentTree;

int main() {
	read(n);read(m);
	for(int i=1;i<=n;i++) read(a[i]);
	Build(1,1,n);
	// puts("GG");
	while(m--) {
		int opt;
		read(opt);
		if(opt==1) {
			int l,r,x,y;
			read(l);read(r);read(x);read(y);
			Modify(1,l,r,x,y);
		}
		else {
			int l,r;
			read(l);read(r);
			printf("%lld\n",Query(1,l,r));
		}
		// puts("Debug :");
		// Debug(1);
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
bool Finish_read;
template<class T>inline void read(T &x){Finish_read=0;x=0;int f=1;char ch=getchar();while(!isdigit(ch)){if(ch=='-')f=-1;if(ch==EOF)return;ch=getchar();}while(isdigit(ch))x=x*10+ch-'0',ch=getchar();x*=f;Finish_read=1;}
template<class T>inline void print(T x){if(x/10!=0)print(x/10);putchar(x%10+'0');}
template<class T>inline void writeln(T x){if(x<0)putchar('-');x=abs(x);print(x);putchar('\n');}
template<class T>inline void write(T x){if(x<0)putchar('-');x=abs(x);print(x);}
/*================Header Template==============*/
#define PAUSE printf("Press Enter key to continue..."); fgetc(stdin);
const int N=1e5+500;
int n,m;
int a[N];
/*==================Define Area================*/
namespace SegmentTree {
	struct node {
		int l,r;
		ll sum[10];
		int to[10];
		void Reset() {
			memset(sum,0,sizeof sum);
		}
		void Init() {
			for(int i=0;i<=9;i++) to[i]=i,sum[i]=0;
		}
		void Print() {
			printf("[%d,%d] --> ",l,r);
			for(int i=0;i<=9;i++) printf("%lld ",sum[i]);
			puts("");
		}
	}t[N<<2];
	ll tmp[10];
	#define ls(o) o<<1
	#define rs(o) o<<1|1
	void Update(int o) {
		t[o].Reset();
		for(int i=0;i<=9;i++) t[o].sum[t[ls(o)].to[i]]+=t[ls(o)].sum[i];
		for(int i=0;i<=9;i++) t[o].sum[t[rs(o)].to[i]]+=t[rs(o)].sum[i];
	}
	void Pushdown(int o) {
		for(int i=0;i<=9;i++) t[ls(o)].to[i]=t[o].to[t[ls(o)].to[i]];
		for(int i=0;i<=9;i++) t[rs(o)].to[i]=t[o].to[t[rs(o)].to[i]];
		memset(tmp,0,sizeof tmp);
		for(int i=0;i<=9;i++) tmp[t[o].to[i]]+=t[o].sum[i];
		for(int i=0;i<=9;i++) t[o].sum[i]=tmp[i];
		for(int i=0;i<=9;i++) t[o].to[i]=i;
	}
	void Build(int o,int l,int r) {
		t[o].l=l;t[o].r=r;t[o].Init();
		if(l==r) {
			int p=a[l],tmp=1;
			while(p) {
				int num=p%10;p/=10;
				t[o].sum[num]+=tmp;tmp*=10;
			}
			return ;
		}
		int mid=(l+r)>>1;
		Build(ls(o),l,mid);
		Build(rs(o),mid+1,r);
		for(int i=0;i<=9;i++) t[o].sum[i]=t[ls(o)].sum[i]+t[rs(o)].sum[i];
		Update(o);
	}
	void Modify(int o,int l,int r,int x,int y) {
		if(t[o].l>=l&&t[o].r<=r) {
			for(int i=0;i<=9;i++) if(t[o].to[i]==x) t[o].to[i]=y;
			return ;
		}
		Pushdown(o);
		int mid=(t[o].l+t[o].r)>>1;
		if(mid>=l) Modify(ls(o),l,r,x,y);
		if(mid<r) Modify(rs(o),l,r,x,y);
		Update(o);
	}
	ll Query(int o,int l,int r) {
		if(t[o].l>=l&&t[o].r<=r) {
			ll res=0;
			for(int i=0;i<=9;i++) res+=(ll)t[o].sum[i]*t[o].to[i];
			return res;
		}
		Pushdown(o);
		int mid=(t[o].l+t[o].r)>>1;
		ll res=0;
		if(mid>=l) res+=Query(ls(o),l,r);
		if(mid<r) res+=Query(rs(o),l,r);
		return res;
	}
	void Debug(int o) {
		if(!o) return ;
		if(!t[o].l) return ;
		Pushdown(o);
		Debug(ls(o));
		t[o].Print();
		Debug(rs(o));
		return ;
	}
}
using namespace SegmentTree;

int main() {
	read(n);read(m);
	for(int i=1;i<=n;i++) read(a[i]);
	Build(1,1,n);
	// puts("GG");
	while(m--) {
		int opt;
		read(opt);
		if(opt==1) {
			int l,r,x,y;
			read(l);read(r);read(x);read(y);
			Modify(1,l,r,x,y);
		}
		else {
			int l,r;
			read(l);read(r);
			printf("%lld\n",Query(1,l,r));
		}
		// puts("Debug :");
		// Debug(1);
	}
	return 0;
}


#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

//typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef double db;

#define int long long
#define fi first
#define se second
#define mp make_pair
#define fastIO std::ios::sync_with_stdio(false);cin.tie(NULL);
#define TEST freopen("in.txt","r",stdin);
#define ones(a) __builtin_popcount(a)

struct Node{
  int sum[10];
  int nx[10];
};

int ch[10];
int pi[10];

struct SegTree{
  Node T[500000];
  int N;

  void Init(int n, int a[]){
    N = 1 << (int)(log2(n - 1) + 1);
    for(int i = 0;i < 500000;i ++ ){
      for(int j = 0;j < 10; j ++ )
        T[i].sum[j] = 0, T[i].nx[j] = j;
    }
    int p = 0;
    int rz;
    int dl;
    for(int j = N;j < N + n; j ++ ){
      dl = a[p];
      rz = 1;
      while(dl > 0){
        T[j].sum[dl%10] += rz;
        rz *= 10ll;
        dl /= 10ll;
      }
      p ++ ;
    }
    for(int j = N-1; j >= 1; j -- ){
      for(int x = 0; x < 10; x ++ ){
        T[j].sum[x] = T[j * 2].sum[x] + T[j * 2 + 1].sum[x];
      }
    }
  }
  void Push(int node, int tl, int tr){
    memset(ch, 0, sizeof ch);
    for(int j = 0;j < 10;j ++ ){
      ch[T[node].nx[j]] += T[node].sum[j];
    }
    for(int j = 0;j < 10; j ++ )
      T[node].sum[j] = ch[j];
    if(tl != tr){
      for(int j = 0;j < 10;j ++ )
        pi[j] = j;
      for(int j = 0;j < 10; j ++ ){
        pi[j] = T[node].nx[T[node * 2].nx[j]];
      }
      for(int j = 0;j < 10;j ++ ){
        T[node * 2].nx[j] = pi[j];
      }
      /* !#@% */
      for(int j = 0;j < 10;j ++ )
        pi[j] = j;
      for(int j = 0;j < 10; j ++ ){
        pi[j] = T[node].nx[T[node * 2 + 1].nx[j]];
      }
      for(int j = 0;j < 10;j ++ ){
        T[node * 2 + 1].nx[j] = pi[j];
      }
    }
  }
  void Update(int node, int cl, int cr, int tl, int tr, int xu, int yu){
    Push(node, cl, cr);
    if(cr < tl)
      return;
    if(cl > tr)
      return;
    if(cl > cr)
      return;
    if(cl >= tl and cr <= tr){
      T[node].nx[xu] = yu;
      Push(node, cl, cr);
      return;
    }
    int md = (cl + cr)/2;
    Update(node * 2, cl, md, tl, tr, xu, yu);
    Update(node * 2 + 1, md + 1, cr, tl, tr, xu, yu);
    for(int j = 0;j < 10; j ++ )
      T[node].sum[j] = T[node * 2].sum[j] + T[node * 2 + 1].sum[j];
  }
  int Ask(int node, int cl, int cr, int tl, int tr){
    Push(node, cl, cr);
    if(cr < tl)
      return 0;
    if(cl > tr)
      return 0;
    if(cl > cr)
      return 0;
    if(cl >= tl and cr <= tr){
      int rez = 0;
      for(int j = 0; j < 10; j ++ ){
        rez += T[node].sum[j] * j;
      }
      return rez;
    }
    int md = (cl + cr)/2;
    return Ask(node * 2, cl, md , tl, tr) + Ask(node * 2 + 1, md + 1, cr, tl, tr);
  }
};

SegTree TR;

signed main(){
  fastIO;
  int n, q;
  cin >> n >> q;
  int k[n];
  for(int i = 0;i < n;i ++ )
    cin >> k[i];
  TR.Init(n, k);
  int ty;
  int l, r, x, y;
  for(int i = 0;i < q; i ++ ){
    cin >> ty;
    if(ty == 1){
      cin >> l >> r >> x >> y;
      --l, --r;
      TR.Update(1, 0, TR.N-1, l, r, x, y);
    }
    else{
      cin >> l >> r;
      --l, --r;
      cout << TR.Ask(1, 0, TR.N-1, l, r) << "\n";
    }
  }
  return 0;
}


#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

//typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef double db;

#define int long long
#define fi first
#define se second
#define mp make_pair
#define fastIO std::ios::sync_with_stdio(false);cin.tie(NULL);
#define TEST freopen("in.txt","r",stdin);
#define ones(a) __builtin_popcount(a)

struct Node{
  int sum[10];
  int nx[10];
};

int ch[10];
int pi[10];

struct SegTree{
  Node T[500000];
  int N;

  void Init(int n, int a[]){
    N = 1 << (int)(log2(n - 1) + 1);
    for(int i = 0;i < 500000;i ++ ){
      for(int j = 0;j < 10; j ++ )
        T[i].sum[j] = 0, T[i].nx[j] = j;
    }
    int p = 0;
    int rz;
    int dl;
    for(int j = N;j < N + n; j ++ ){
      dl = a[p];
      rz = 1;
      while(dl > 0){
        T[j].sum[dl%10] += rz;
        rz *= 10;
        dl /= 10;
      }
      p ++ ;
    }
    for(int j = N-1; j >= 1; j -- ){
      for(int x = 0; x < 10; x ++ ){
        T[j].sum[x] = T[j * 2].sum[x] + T[j * 2 + 1].sum[x];
      }
    }
  }
  void Push(int node, int tl, int tr){
    memset(ch, 0, sizeof ch);
    for(int j = 0;j < 10;j ++ ){
      ch[T[node].nx[j]] += T[node].sum[j];
    }
    for(int j = 0;j < 10; j ++ )
      T[node].sum[j] = ch[j];
    if(tl != tr){
      for(int j = 0;j < 10;j ++ )
        pi[j] = j;
      for(int j = 0;j < 10; j ++ ){
        pi[j] = T[node].nx[T[node * 2].nx[j]];
      }
      for(int j = 0;j < 10;j ++ ){
        T[node * 2].nx[j] = pi[j];
      }
      /* !#@% */
      for(int j = 0;j < 10;j ++ )
        pi[j] = j;
      for(int j = 0;j < 10; j ++ ){
        pi[j] = T[node].nx[T[node * 2 + 1].nx[j]];
      }
      for(int j = 0;j < 10;j ++ ){
        T[node * 2 + 1].nx[j] = pi[j];
      }
    }
  }
  void Update(int node, int cl, int cr, int tl, int tr, int xu, int yu){
    Push(node, cl, cr);
    if(cr < tl)
      return;
    if(cl > tr)
      return;
    if(cl > cr)
      return;
    if(cl >= tl and cr <= tr){
      T[node].nx[xu] = yu;
      Push(node, cl, cr);
      return;
    }
    int md = (cl + cr)/2;
    Update(node * 2, cl, md, tl, tr, xu, yu);
    Update(node * 2 + 1, md + 1, cr, tl, tr, xu, yu);
    for(int j = 0;j < 10; j ++ )
      T[node].sum[j] = T[node * 2].sum[j] + T[node * 2 + 1].sum[j];
  }
  int Ask(int node, int cl, int cr, int tl, int tr){
    Push(node, cl, cr);
    if(cr < tl)
      return 0;
    if(cl > tr)
      return 0;
    if(cl > cr)
      return 0;
    if(cl >= tl and cr <= tr){
      int rez = 0;
      for(int j = 0; j < 10; j ++ ){
        rez += T[node].sum[j] * j;
      }
      return rez;
    }
    int md = (cl + cr)/2;
    return Ask(node * 2, cl, md , tl, tr) + Ask(node * 2 + 1, md + 1, cr, tl, tr);
  }
};

SegTree TR;

signed main(){
  fastIO;
  int n, q;
  cin >> n >> q;
  int k[n];
  for(int i = 0;i < n;i ++ )
    cin >> k[i];
  TR.Init(n, k);
  int ty;
  int l, r, x, y;
  for(int i = 0;i < q; i ++ ){
    cin >> ty;
    if(ty == 1){
      cin >> l >> r >> x >> y;
      --l, --r;
      TR.Update(1, 0, TR.N-1, l, r, x, y);
    }
    else{
      cin >> l >> r;
      --l, --r;
      cout << TR.Ask(1, 0, TR.N-1, l, r) << "\n";
    }
  }
  return 0;
}


#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

//typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef double db;

#define int long long
#define fi first
#define se second
#define mp make_pair
#define fastIO std::ios::sync_with_stdio(false);cin.tie(NULL);
#define TEST freopen("in.txt","r",stdin);
#define ones(a) __builtin_popcount(a)

struct Node{
  int sum[10];
  int nx[10];
};

int ch[10];
int pi[10];

struct SegTree{
  Node T[1000000];
  int N;

  void Init(int n, int a[]){
    N = 1 << (int)(log2(n) + 1);
    for(int i = 0;i < 500000;i ++ ){
      for(int j = 0;j < 10; j ++ )
        T[i].sum[j] = 0, T[i].nx[j] = j;
    }
    int p = 0;
    int rz;
    int dl;
    for(int j = N;j < N + n; j ++ ){
      dl = a[p];
      rz = 1;
      while(dl > 0){
        T[j].sum[dl%10] += rz;
        rz *= 10ll;
        dl /= 10ll;
      }
      p ++ ;
    }
    for(int j = N-1; j >= 1; j -- ){
      for(int x = 0; x < 10; x ++ ){
        T[j].sum[x] = T[j * 2].sum[x] + T[j * 2 + 1].sum[x];
      }
    }
  }
  void Push(int node, int tl, int tr){
    memset(ch, 0, sizeof ch);
    for(int j = 0;j < 10;j ++ ){
      ch[T[node].nx[j]] += T[node].sum[j];
    }
    for(int j = 0;j < 10; j ++ )
      T[node].sum[j] = ch[j];
    if(tl != tr){
      for(int j = 0;j < 10;j ++ )
        pi[j] = j;
      for(int j = 0;j < 10; j ++ ){
        pi[j] = T[node].nx[T[node * 2].nx[j]];
      }
      for(int j = 0;j < 10;j ++ ){
        T[node * 2].nx[j] = pi[j];
      }
      /* !#@% */
      for(int j = 0;j < 10;j ++ )
        pi[j] = j;
      for(int j = 0;j < 10; j ++ ){
        pi[j] = T[node].nx[T[node * 2 + 1].nx[j]];
      }
      for(int j = 0;j < 10;j ++ ){
        T[node * 2 + 1].nx[j] = pi[j];
      }
    }
  }
  void Update(int node, int cl, int cr, int tl, int tr, int xu, int yu){
    Push(node, cl, cr);
    if(cr < tl)
      return;
    if(cl > tr)
      return;
    if(cl > cr)
      return;
    if(cl >= tl and cr <= tr){
      T[node].nx[xu] = yu;
      Push(node, cl, cr);
      return;
    }
    int md = (cl + cr)/2;
    Update(node * 2, cl, md, tl, tr, xu, yu);
    Update(node * 2 + 1, md + 1, cr, tl, tr, xu, yu);
    for(int j = 0;j < 10; j ++ )
      T[node].sum[j] = T[node * 2].sum[j] + T[node * 2 + 1].sum[j];
  }
  int Ask(int node, int cl, int cr, int tl, int tr){
    Push(node, cl, cr);
    if(cr < tl)
      return 0;
    if(cl > tr)
      return 0;
    if(cl > cr)
      return 0;
    if(cl >= tl and cr <= tr){
      int rez = 0;
      for(int j = 0; j < 10; j ++ ){
        rez += T[node].sum[j] * j;
      }
      return rez;
    }
    int md = (cl + cr)/2;
    return Ask(node * 2, cl, md , tl, tr) + Ask(node * 2 + 1, md + 1, cr, tl, tr);
  }
};

SegTree TR;

signed main(){
  fastIO;
  int n, q;
  cin >> n >> q;
  int k[n];
  for(int i = 0;i < n;i ++ )
    cin >> k[i];
  TR.Init(n, k);
  int ty;
  int l, r, x, y;
  for(int i = 0;i < q; i ++ ){
    cin >> ty;
    if(ty == 1){
      cin >> l >> r >> x >> y;
      --l, --r;
      TR.Update(1, 0, TR.N-1, l, r, x, y);
    }
    else{
      cin >> l >> r;
      --l, --r;
      cout << TR.Ask(1, 0, TR.N-1, l, r) << "\n";
    }
  }
  return 0;
}


#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef double db;

#define fi first
#define se second
#define mp make_pair
#define fastIO std::ios::sync_with_stdio(false);cin.tie(NULL);
#define TEST freopen("in.txt","r",stdin);
#define ones(a) __builtin_popcount(a)

struct Node{
  ll sum[10];
  int nx[10];
};

ll ch[10];
int pi[10];

struct SegTree{
  Node T[500000];
  int N;

  void Init(int n, ll a[]){
    N = 1 << int(log2(n - 1) + 1);
    for(int i = 0;i < 500000;i ++ ){
      for(int j = 0;j < 10; j ++ )
        T[i].sum[j] = 0, T[i].nx[j] = j;
    }
    int p = 0;
    ll rz;
    ll dl;
    for(int j = N;j < N + n; j ++ ){
      dl = a[p];
      rz = 1;
      while(dl > 0){
        T[j].sum[dl%10] += rz;
        rz *= 10;
        dl /= 10;
      }
      p ++ ;
    }
    for(int j = N-1; j >= 1; j -- ){
      for(int x = 0; x < 10; x ++ ){
        T[j].sum[x] = T[j * 2].sum[x] + T[j * 2 + 1].sum[x];
      }
    }
  }
  void Push(int node, int tl, int tr){
    memset(ch, 0, sizeof ch);
    for(int j = 0;j < 10;j ++ ){
      ch[T[node].nx[j]] += T[node].sum[j];
    }
    for(int j = 0;j < 10; j ++ )
      T[node].sum[j] = ch[j];
    if(tl != tr){
      for(int j = 0;j < 10;j ++ )
        pi[j] = j;
      for(int j = 0;j < 10; j ++ ){
        pi[j] = T[node].nx[T[node * 2].nx[j]];
      }
      for(int j = 0;j < 10;j ++ ){
        T[node * 2].nx[j] = pi[j];
      }
      /* !#@% */
      for(int j = 0;j < 10;j ++ )
        pi[j] = j;
      for(int j = 0;j < 10; j ++ ){
        pi[j] = T[node].nx[T[node * 2 + 1].nx[j]];
      }
      for(int j = 0;j < 10;j ++ ){
        T[node * 2 + 1].nx[j] = pi[j];
      }
    }
    for(int j = 0;j < 10;j ++ )
      T[node].nx[j] = j;
  }
  void Update(int node, int cl, int cr, int tl, int tr, int xu, int yu){
    Push(node, cl, cr);
    if(cr < tl)
      return;
    if(cl > tr)
      return;
    if(cl > cr)
      return;
    if(cl >= tl and cr <= tr){
      T[node].nx[xu] = yu;
      Push(node, cl, cr);
      return;
    }
    int md = (cl + cr)/2;
    Update(node * 2, cl, md, tl, tr, xu, yu);
    Update(node * 2 + 1, md + 1, cr, tl, tr, xu, yu);
    for(int j = 0;j < 10; j ++ )
      T[node].sum[j] = T[node * 2].sum[j] + T[node * 2 + 1].sum[j];
  }
  ll Ask(int node, int cl, int cr, int tl, int tr){
    Push(node, cl, cr);
    if(cr < tl)
      return 0;
    if(cl > tr)
      return 0;
    if(cl > cr)
      return 0;
    if(cl >= tl and cr <= tr){
      ll rez = 0;
      for(int j = 0; j < 10; j ++ ){
        rez += T[node].sum[j] * j;
      }
      return rez;
    }
    int md = (cl + cr)/2;
    return Ask(node * 2, cl, md , tl, tr) + Ask(node * 2 + 1, md + 1, cr, tl, tr);
  }
};

SegTree TR;

int main(){
  fastIO;
  int n, q;
  cin >> n >> q;
  ll k[n];
  for(int i = 0;i < n;i ++ )
    cin >> k[i];
  TR.Init(n, k);
  int ty;
  int l, r, x, y;
  for(int i = 0;i < q; i ++ ){
    cin >> ty;
    if(ty == 1){
      cin >> l >> r >> x >> y;
      --l, --r;
      TR.Update(1, 0, TR.N-1, l, r, x, y);
    }
    else{
      cin >> l >> r;
      --l, --r;
      cout << TR.Ask(1, 0, TR.N-1, l, r) << "\n";
    }
  }
  return 0;
}


#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef double db;

#define fi first
#define se second
#define mp make_pair
#define fastIO std::ios::sync_with_stdio(false);cin.tie(NULL);
#define TEST freopen("in.txt","r",stdin);
#define ones(a) __builtin_popcount(a)

struct Node{
  ll sum[10];
  int nx[10];
};

ll ch[10];
int pi[10];

struct SegTree{
  Node T[500000];
  int N;

  void Init(int n, ll a[]){
    N = 1 << int(log2(n - 1) + 1);
    for(int i = 0;i < 500000;i ++ ){
      for(int j = 0;j < 10; j ++ )
        T[i].sum[j] = 0, T[i].nx[j] = j;
    }
    int p = 0;
    ll rz;
    ll dl;
    for(int j = N;j < N + n; j ++ ){
      dl = a[p];
      rz = 1;
      while(dl > 0){
        T[j].sum[dl%10] += rz;
        rz *= 10;
        dl /= 10;
      }
      p ++ ;
    }
    for(int j = N-1; j >= 1; j -- ){
      for(int x = 0; x < 10; x ++ ){
        T[j].sum[x] = T[j * 2].sum[x] + T[j * 2 + 1].sum[x];
      }
    }
  }
  void Push(int node, int tl, int tr){
    memset(ch, 0, sizeof ch);
    for(int j = 0;j < 10;j ++ ){
      ch[T[node].nx[j]] += T[node].sum[j];
    }
    for(int j = 0;j < 10; j ++ )
      T[node].sum[j] = ch[j];
    if(tl != tr){
      for(int j = 0;j < 10;j ++ )
        pi[j] = j;
      for(int j = 0;j < 10; j ++ ){
        pi[j] = T[node].nx[T[node * 2].nx[j]];
      }
      for(int j = 0;j < 10;j ++ ){
        T[node * 2].nx[j] = pi[j];
      }
      /* !#@% */
      for(int j = 0;j < 10;j ++ )
        pi[j] = j;
      for(int j = 0;j < 10; j ++ ){
        pi[j] = T[node].nx[T[node * 2 + 1].nx[j]];
      }
      for(int j = 0;j < 10;j ++ ){
        T[node * 2 + 1].nx[j] = pi[j];
      }
    }
  }
  void Update(int node, int cl, int cr, int tl, int tr, int xu, int yu){
    Push(node, cl, cr);
    if(cr < tl)
      return;
    if(cl > tr)
      return;
    if(cl > cr)
      return;
    if(cl >= tl and cr <= tr){
      T[node].nx[xu] = yu;
      Push(node, cl, cr);
      return;
    }
    int md = (cl + cr)/2;
    Update(node * 2, cl, md, tl, tr, xu, yu);
    Update(node * 2 + 1, md + 1, cr, tl, tr, xu, yu);
    for(int j = 0;j < 10; j ++ )
      T[node].sum[j] = T[node * 2].sum[j] + T[node * 2 + 1].sum[j];
  }
  ll Ask(int node, int cl, int cr, int tl, int tr){
    Push(node, cl, cr);
    if(cr < tl)
      return 0;
    if(cl > tr)
      return 0;
    if(cl > cr)
      return 0;
    if(cl >= tl and cr <= tr){
      ll rez = 0;
      for(int j = 0; j < 10; j ++ ){
        rez += T[node].sum[j] * j;
      }
      return rez;
    }
    int md = (cl + cr)/2;
    return Ask(node * 2, cl, md , tl, tr) + Ask(node * 2 + 1, md + 1, cr, tl, tr);
  }
};

SegTree TR;

int main(){
  fastIO;
  int n, q;
  cin >> n >> q;
  ll k[n];
  for(int i = 0;i < n;i ++ )
    cin >> k[i];
  TR.Init(n, k);
  int ty;
  int l, r, x, y;
  for(int i = 0;i < q; i ++ ){
    cin >> ty;
    if(ty == 1){
      cin >> l >> r >> x >> y;
      --l, --r;
      TR.Update(1, 0, TR.N-1, l, r, x, y);
    }
    else{
      cin >> l >> r;
      --l, --r;
      cout << TR.Ask(1, 0, TR.N-1, l, r) << "\n";
    }
  }
  return 0;
}