#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>

using namespace std;

const int MaxN = 1000005;

int n;
int d;
char str[MaxN];

int cnt[10];
int tmp[10];

int nxt;
int a[MaxN];
int b[MaxN];
int mark[MaxN];
int used[MaxN];

int sz = 0;
int need[MaxN];

vector<int> notMarkNumber;
vector<int> notUsedSpace;

int fin[1000005];

int main() {
    freopen("sorti.in", "r", stdin);
    freopen("sorti.out", "w", stdout);
    scanf("%d%d", &n, &d);
    scanf("%s", &str);
    memset(cnt, 0, sizeof(cnt));
    for (int i = 0; i < n; ++i)
        ++cnt[str[i] - '0'];
    for (int i = 0; i < 10; ++i)
        for (int j = 0; j < cnt[i]; ++j) {
            need[sz] = i;
            ++sz;
        }
    int res = 0;
    memset(fin, -1, sizeof(fin));
    memset(used, 0, sizeof(used));
    memset(mark, 0, sizeof(mark));
    for (int i = 0; i < d; ++i) {
        nxt = 0;
        memset(cnt, 0, sizeof(cnt));
        memset(tmp, 0, sizeof(tmp));
        for (int j = i; j < n; j += d) {
            a[nxt] = j;
            b[nxt] = need[j];
            ++cnt[str[j] - '0'];
            ++nxt;
        }
        for (int j = 0; j < nxt; ++j) {
            if (cnt[b[j]]) {
                ++tmp[b[j]];
                --cnt[b[j]];
                used[a[j]] = true;
            }
        }
        for (int j = 0; j < nxt; ++j)
            if (tmp[str[a[j]] - '0']) {
                mark[a[j]] = true;
                --tmp[str[a[j]] - '0'];
            }
        notMarkNumber.clear();
        notUsedSpace.clear();
        for (int j = 0; j < nxt; ++j) {
            if (!mark[a[j]])
                ++res;
            if (!mark[a[j]]) notMarkNumber.push_back(a[j]);
            if (!used[a[j]]) notUsedSpace.push_back(a[j]);
        }
        int size = notMarkNumber.size();
        for (int j = 0; j < size; ++j)
            fin[notUsedSpace[j]] = notMarkNumber[j];
    }
    printf("%d\n", res);
    for (int i = 0; i < n; ++i)
        if (fin[i] != -1)
            printf("%d %d\n", fin[i] + 1, need[i]);
    return 0;
}
