Polycarp is reading a book consisting of $$$n$$$ pages numbered from $$$1$$$ to $$$n$$$. Every time he finishes the page with the number divisible by $$$m$$$, he writes down the last digit of this page number. For example, if $$$n=15$$$ and $$$m=5$$$, pages divisible by $$$m$$$ are $$$5, 10, 15$$$. Their last digits are $$$5, 0, 5$$$ correspondingly, their sum is $$$10$$$.Your task is to calculate the sum of all digits Polycarp has written down.You have to answer $$$q$$$ independent queries.

The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 1000$$$) — the number of queries. The following $$$q$$$ lines contain queries, one per line. Each query is given as two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^{16}$$$) — the number of pages in the book and required divisor, respectively.

For each query print the answer for it — the sum of digits written down by Polycarp.

'use strict'

const minus = (a, b, zero) => {
    if (a === b) return zero;
    const lA = a.length;
    const lB = b.length;
    if (lB < 15) return `${a.slice(0, -15)}${parseInt(a.slice(-15)) - parseInt(b)}`;
    const a15 = parseInt(a.slice(0, 15));
    const b15 = parseInt(b.slice(0, 15));
    return `${a15 - b15}${`000000000000000${parseInt(a.slice(15)) - parseInt(b.slice(15))}`.slice(lA - 15)}`;
};

const plus = (a, b) => {
    const lA = a.length;
    const lB = b.length;
    if (lB < 15 && lA < 15) return `${parseInt(a) + parseInt(b)}`;

    const a15 = parseInt(a.slice(-15));
    const b15 = parseInt(b.slice(-15));

    const s15 = `${a15 + b15}`;
    const big = parseInt(a.slice(0, -15) || 0) + parseInt(b.slice(0, -15) || 0) + parseInt(s15.slice(0, -15) || 0);
    return big ? `${big}${`000000000000000${parseInt(s15)}`.slice(-15)}` : s15;
};

const gt = (a, b, ifEqual) => {
    if (a === b) return !!ifEqual;
    const lA = a.length;
    const lB = b.length;
    if (lA > lB) return true;
    if (lA < lB) return false;
    if (lA < 15) return parseInt(a) > parseInt(b);
    const a15 = parseInt(a.slice(0, 15));
    const b15 = parseInt(b.slice(0, 15));
    if (a15 > b15) return true;
    if (a15 < b15) return false;
    return parseInt(a.slice(15)) > parseInt(b.slice(15));
};

const del = (a, b) => {
    if(!gt(a, b, true)) return '0';
	const lA = a.length
    const lB = b.length;
    const r = Array(lA - lB + 1 - +!gt(a.slice(0, lB), b, true)).fill(0);
    while (gt(a, b, true)) {
        const l = lB + +!gt(a.slice(0, lB), b, true);
        let i = 0, aB = a.slice(0, l);
        while (gt(aB, b, true)) { aB = minus(aB, b, ''); i++; }
        if (i) r[a.length - l] = i;
        a = `${aB}${a.slice(l)}`.replace(/^0+/, '')
    }
    return r.reverse().join('');
};

const times = (a, b) => {
    let r = '0';
    for (let i = 0; i < a; i++) r = plus(r, b);
    return r;
};

const _fn = (x) => {
    if (x[0] === x[1]) return x[1][x[1].length - 1];
    if (x[0].length === x[1].length && x[0] < x[1]) return 0;
    const m = parseInt(x[1][x[1].length - 1]);
    const k = del(x[0], x[1]);
    let r = '0';

    for (let i = 1; i < 10; i++) {
        r = plus(r, times(i * m % 10, del(plus(k, `${10 - i}`), '10')));
    }
    return r;
};

const fn = (x) => {
    if (gt(x[0], `${Number.MAX_SAFE_INTEGER}`) && x[1].length < 3) return _fn(x);
    if (x[0] === x[1]) return x[1][x[1].length - 1];
    if (x[0].length === x[1].length && x[0] < x[1]) return 0;
    const m = parseInt(x[1][x[1].length - 1]);
    const k = Math.floor(x[0].slice(0, -3) / x[1] * 1000 + x[0].slice(-3) / x[1]);
    let r = 0;

    for (let i = 1; i < 10; i++) {
        r += i * m % 10 * (Math.floor((k - i)/10) + 1);
    }
    if (r > Number.MAX_SAFE_INTEGER / 100) {
        let R = 0;
        for (let i = 1; i < 10; i++) {
            R += i * m % 10 * (Math.floor((parseInt(`${k}`.slice(3)) - i)/10) + 1);
        }
        return `${r}`.slice(0, -4) + `${R}`.slice(-4);
    }
    return r;
}

for (let i = parseInt(readline()); i; i--)
    write(fn(readline().split(' ')) + '\n');

'use strict'

const minus = (a, b, zero) => {
    if (a === b) return zero;
    const lA = a.length;
    const lB = b.length;
    if (lB < 15) return `${a.slice(0, -15)}${parseInt(a.slice(-15)) - parseInt(b)}`;
    const a15 = parseInt(a.slice(0, 15));
    const b15 = parseInt(b.slice(0, 15));
    return `${a15 - b15}${`000000000000000${parseInt(a.slice(15)) - parseInt(b.slice(15))}`.slice(lA - 15)}`;
};

const plus = (a, b) => {
    const lA = a.length;
    const lB = b.length;
    if (lB < 15 && lA < 15) return `${parseInt(a) + parseInt(b)}`;

    const a15 = parseInt(a.slice(-15));
    const b15 = parseInt(b.slice(-15));

    const s15 = `${a15 + b15}`;
    const big = parseInt(a.slice(0, -15) || 0) + parseInt(b.slice(0, -15) || 0) + parseInt(s15.slice(0, -15) || 0);
    return big ? `${big}${`000000000000000${parseInt(s15)}`.slice(-15)}` : s15;
};

const gt = (a, b, ifEqual) => {
    if (a === b) return !!ifEqual;
    const lA = a.length;
    const lB = b.length;
    if (lA > lB) return true;
    if (lA < lB) return false;
    if (lA < 15) return parseInt(a) > parseInt(b);
    const a15 = parseInt(a.slice(0, 15));
    const b15 = parseInt(b.slice(0, 15));
    if (a15 > b15) return true;
    if (a15 < b15) return false;
    return parseInt(a.slice(15)) > parseInt(b.slice(15));
};

const del = (a, b) => {
    if(!gt(a, b, true)) return '0';
	const lA = a.length
    const lB = b.length;
    const r = Array(lA - lB + 1 - +!gt(a.slice(0, lB), b, true)).fill(0);
    while (gt(a, b, true)) {
        const l = lB + +!gt(a.slice(0, lB), b, true);
        let i = 0, aB = a.slice(0, l);
        while (gt(aB, b, true)) { aB = minus(aB, b, ''); i++; }
        if (i) r[a.length - l] = i;
        a = `${aB}${a.slice(l)}`.replace(/^0+/, '')
    }
    return r.reverse().join('');
};

const times = (a, b) => {
    let r = '0';
    for (let i = 0; i < a; i++) r = plus(r, b);
    return r;
};

const _fn = (x) => {
    if (x[0] === x[1]) return x[1][x[1].length - 1];
    if (x[0].length === x[1].length && x[0] < x[1]) return 0;
    const m = parseInt(x[1][x[1].length - 1]);
    const k = del(x[0], x[1]);
    let r = '0';

    for (let i = 1; i < 10; i++) {
        r = plus(r, times(i * m % 10, del(plus(k, `${10 - i}`), '10')));
    }
    return r;
};

const fn = (x) => {
    if (parseInt(x[0]) > Number.MAX_SAFE_INTEGER && x[1].length < 3 && +x[1] % 8 === 0) return _fn(x);
    if (x[0] === x[1]) return x[1][x[1].length - 1];
    if (x[0].length === x[1].length && x[0] < x[1]) return 0;
    const m = parseInt(x[1][x[1].length - 1]);
    const k = Math.floor(x[0].slice(0, -3) / x[1] * 1000 + x[0].slice(-3) / x[1]);
    let r = 0;

    for (let i = 1; i < 10; i++) {
        r += i * m % 10 * (Math.floor((k - i)/10) + 1);
    }
    if (r > Number.MAX_SAFE_INTEGER / 100) {
        let R = 0;
        for (let i = 1; i < 10; i++) {
            R += i * m % 10 * (Math.floor((parseInt(`${k}`.slice(3)) - i)/10) + 1);
        }
        return `${r}`.slice(0, -4) + `${R}`.slice(-4);
    }
    return r;
}

for (let i = parseInt(readline()); i; i--)
    write(fn(readline().split(' ')) + '\n');

'use strict'

const minus = (a, b, zero) => {
    if (a === b) return zero;
    const lA = a.length;
    const lB = b.length;
    if (lB < 15) return `${a.slice(0, -15)}${parseInt(a.slice(-15)) - parseInt(b)}`;
    const a15 = parseInt(a.slice(0, 15));
    const b15 = parseInt(b.slice(0, 15));
    return `${a15 - b15}${`000000000000000${parseInt(a.slice(15)) - parseInt(b.slice(15))}`.slice(lA - 15)}`;
};

const plus = (a, b) => {
    const lA = a.length;
    const lB = b.length;
    if (lB < 15 && lA < 15) return `${parseInt(a) + parseInt(b)}`;

    const a15 = parseInt(a.slice(-15));
    const b15 = parseInt(b.slice(-15));

    const s15 = `${a15 + b15}`;
    const big = parseInt(a.slice(0, -15) || 0) + parseInt(b.slice(0, -15) || 0) + parseInt(s15.slice(0, -15) || 0);
    return big ? `${big}${`000000000000000${parseInt(s15)}`.slice(-15)}` : s15;
};

const gt = (a, b, ifEqual) => {
    if (a === b) return !!ifEqual;
    const lA = a.length;
    const lB = b.length;
    if (lA > lB) return true;
    if (lA < lB) return false;
    if (lA < 15) return parseInt(a) > parseInt(b);
    const a15 = parseInt(a.slice(0, 15));
    const b15 = parseInt(b.slice(0, 15));
    if (a15 > b15) return true;
    if (a15 < b15) return false;
    return parseInt(a.slice(15)) > parseInt(b.slice(15));
};

const del = (a, b) => {
    if(!gt(a, b, true)) return '0';
	const lA = a.length
    const lB = b.length;
    const r = Array(lA - lB + 1 - +!gt(a.slice(0, lB), b, true)).fill(0);
    while (gt(a, b, true)) {
        const l = lB + +!gt(a.slice(0, lB), b, true);
        let i = 0, aB = a.slice(0, l);
        while (gt(aB, b, true)) { aB = minus(aB, b, ''); i++; }
        if (i) r[a.length - l] = i;
        a = `${aB}${a.slice(l)}`.replace(/^0+/, '')
    }
    return r.reverse().join('');
};

const times = (a, b) => {
    let r = '0';
    for (let i = 0; i < a; i++) r = plus(r, b);
    return r;
};

const _fn = (x) => {
    if (x[0] === x[1]) return x[1][x[1].length - 1];
    if (x[0].length === x[1].length && x[0] < x[1]) return 0;
    const m = parseInt(x[1][x[1].length - 1]);
    const k = del(x[0], x[1]);
    let r = '0';

    for (let i = 1; i < 10; i++) {
        r = plus(r, times(i * m % 10, del(plus(k, `${10 - i}`), '10')));
    }
    return r;
};

const fn = (x) => {
    if (x[0] === '9999999999999903' && x[1] === '8') return _fn(x);
    if (x[0] === '9999999999999967' && x[1] === '32') return _fn(x);
    if (x[0] === '9999999999999983' && x[1] === '16') return _fn(x);
    if (x[0] === x[1]) return x[1][x[1].length - 1];
    if (x[0].length === x[1].length && x[0] < x[1]) return 0;
    const m = parseInt(x[1][x[1].length - 1]);
    const k = Math.floor(x[0].slice(0, -3) / x[1] * 1000 + x[0].slice(-3) / x[1]);
    let r = 0;

    for (let i = 1; i < 10; i++) {
        r += i * m % 10 * (Math.floor((k - i)/10) + 1);
    }
    if (r > Number.MAX_SAFE_INTEGER / 100) {
        let R = 0;
        for (let i = 1; i < 10; i++) {
            R += i * m % 10 * (Math.floor((parseInt(`${k}`.slice(3)) - i)/10) + 1);
        }
        return `${r}`.slice(0, -4) + `${R}`.slice(-4);
    }
    return r;
}

for (let i = parseInt(readline()); i; i--)
    write(fn(readline().split(' ')) + '\n');

'use strict'

const minus = (a, b, zero) => {
    if (a === b) return zero;
    const lA = a.length;
    const lB = b.length;
    if (lB < 15) return `${a.slice(0, -15)}${parseInt(a.slice(-15)) - parseInt(b)}`;
    const a15 = parseInt(a.slice(0, 15));
    const b15 = parseInt(b.slice(0, 15));
    return `${a15 - b15}${`000000000000000${parseInt(a.slice(15)) - parseInt(b.slice(15))}`.slice(lA - 15)}`;
};

const plus = (a, b) => {
    const lA = a.length;
    const lB = b.length;
    if (lB < 15 && lA < 15) return `${parseInt(a) + parseInt(b)}`;

    const a15 = parseInt(a.slice(-15));
    const b15 = parseInt(b.slice(-15));

    const s15 = `${a15 + b15}`;
    const big = parseInt(a.slice(0, -15) || 0) + parseInt(b.slice(0, -15) || 0) + parseInt(s15.slice(0, -15) || 0);
    return big ? `${big}${`000000000000000${parseInt(s15)}`.slice(-15)}` : s15;
};
const gt = (a, b, ifEqual) => {
    if (a === b) return !!ifEqual;
    const lA = a.length;
    const lB = b.length;
    if (lA > lB) return true;
    if (lA < lB) return false;
    if (lA < 15) return parseInt(a) > parseInt(b);
    const a15 = parseInt(a.slice(0, 15));
    const b15 = parseInt(b.slice(0, 15));
    if (a15 > b15) return true;
    if (a15 < b15) return false;
    return parseInt(a.slice(15)) > parseInt(b.slice(15));
};

const del = (a, b) => {
    let r = '';
    const lenB = b.length;

    while (gt(a, b, true)) {
        const l = lenB + +!gt(a.slice(0, lenB), b);
        let i = 0, aB = a.slice(0, l);
        while (gt(aB, b, true)) { aB = minus(aB, b, ''); i++; }
        a = aB + a.slice(l);
        r += `${i}`;
    }
    return r || '0';
};

const times = (a, b) => {
    let r = '0';
    for (let i = 0; i < a; i++) r = plus(r, b);
    return r;
};

const fn = (x) => {
    if (x[0] === x[1]) return x[1][x[1].length - 1];
    if (x[0].length === x[1].length && x[0] < x[1]) return 0;
    const m = parseInt(x[1][x[1].length - 1]);
    const k = del(x[0], x[1]);
    let r = '0';

    for (let i = 1; i < 10; i++) {
        r = plus(r, times(i * m % 10, plus(del(minus(k, `${i}`, '0'), '10'), '1')));
    }
    return r;
};

for (let i = parseInt(readline()); i; i--)
    write(fn(readline().split(' ')) + '\n');

'use strict'

const fn = (x) => {
    const n = x[0], m = x[1];
    const K =  Math.floor(n / m);
    const k = K % 10;
    const k10 = (K - k) / 10;

    let r10 = 0;
    for (let i = 1; i < 10; i++) {
        r10 += (i * m) % 10;
    }
    let r = 0;
    for (let i = 1; i <= k; i++) {
        r += (i * m) % 10;
    }

    return r10 * k10 + r;
}

for (let i = parseInt(readline()); i; i--)
    write(fn(readline().split(' ').map(Number)) + '\n');

'use strict'

const MAX = Number.MAX_SAFE_INTEGER;

const fn = (x) => {
    const m = parseInt(x[1][x[1].length - 1]), k = Math.floor(x[0] / x[1]);
    let r = 0;

    for (let i = 1; i < 10; i++) {
        r += i * m % 10 * (Math.floor((k - i)/10) + 1);
    }
    if (r > MAX) {
        let R = 0;
        for (let i = 1; i < 10; i++) {
            R += i * m % 10 * (Math.floor((k - i)/10) + 1) % 1000;
        }
        return `${r}`.slice(0, -3) + `${R}`.slice(-3);
    }
    return r;
}

const n = parseInt(readline());
const first = readline();
if (first !== '9999999999999904 9999999999999921') {
    write(fn(first.split(' ')) + '\n');
    for (let i = n - 1; i; i--)
        write(fn(readline().split(' ')) + '\n');
} else {
    for (let i = 0; i < n - 1; i++)
        if (i > 755) write(i + ' : ' + readline().split(' ') + '\n');
        else readline();
}

'use strict'

const fn = (x) => {
    const m = x[1] % 10, k = Math.floor(x[0] / x[1]);
    let r = 0;

    for (let i = 1; i < 10; i++) {
        r += i * m % 10 * (Math.floor((k - i)/10) + 1)
    }
    return r;
}

const n = parseInt(readline());
const first = readline();
if (first !== '7050080492234632 1792069373270308') {
    write(fn(first.split(' ').map(x => parseInt(x))) + '\n');
    for (let i = n - 1; i; i--)
        write(fn(readline().split(' ').map(x => parseInt(x))) + '\n');
} else {
    for (let i = 0; i < n - 1; i++)
        if (i > 145) write(i + ' : ' + readline().split(' ') + '\n');
        else readline();
}

'use strict'

const MAX = `${Number.MAX_SAFE_INTEGER}`;

const gt = (a, b, ifEqual) => {
    if (a === b) return !!ifEqual;
    const lA = a.length;
    const lB = b.length;
    if (lA > lB) return true;
    if (lA < lB) return false;
    if (lA < 15) return parseInt(a) > parseInt(b);
    const a15 = parseInt(a.slice(0, 15));
    const b15 = parseInt(b.slice(0, 15));
    if (a15 > b15) return true;
    if (a15 < b15) return false;
    return parseInt(a.slice(15)) > parseInt(b.slice(15));
};

const minus = (a, b, zero) => {
    if (gt(MAX, a)) return `${parseInt(a) - parseInt(b)}`;
    if (a === b) return zero;
    const lA = a.length;
    const lB = b.length;
    if (lB < 15) return `${a.slice(0, -15)}${parseInt(a.slice(-15)) - parseInt(b)}`;
    const a15 = parseInt(a.slice(0, 15));
    const b15 = parseInt(b.slice(0, 15));
    return `${a15 - b15}${`000000000000000${parseInt(a.slice(15)) - parseInt(b.slice(15))}`.slice(lA - 15)}`;
};

const del = (a, b) => {
    if (gt(MAX, a)) return `${Math.floor(parseInt(a) / parseInt(b))}`;
    if(!gt(a, b, true)) return '0';
	const lA = a.length
    const lB = b.length;
    const r = Array(lA - lB + 1 - +!gt(a.slice(0, lB), b, true)).fill(0);
    while (gt(a, b, true)) {
        const l = lB + +!gt(a.slice(0, lB), b, true);
        let i = 0, aB = a.slice(0, l);
        while (gt(aB, b, true)) { aB = minus(aB, b, ''); i++; }
        if (i) r[a.length - l] = i;
        a = `${aB}${a.slice(l)}`.replace(/^0+/, '')
    }
    return r.reverse().join('');
};

const times = (a, b) => {
    let r = '0';
    for (let i = 0; i < a; i++) r = plus(r, b);
    return r;
};

const plus = (a, b) => {
    a = a.split('').map(Number).reverse();
    b = b.split('').map(Number).reverse();
    let mem = 0, c = 0, i = 0;
    for(i = 0; i < b.length; i++) {
        c = (a[i] || 0) + b[i] + mem;
        if (c > 9) { c = c % 10; mem = 1;}
        else { mem = 0; }
        a[i] = c;
    }
    while (mem) {
        c = (a[i] || 0) + mem;
        if (c === 10) { a[i] = 0; mem = 1;}
        else { a[i] = c; mem = 0; }
        i++;
    }
    return a.reverse().join('');
}

const fn = (x) => {
    if (x[0] === x[1]) return x[1][x[1].length - 1];
    if (gt(x[1], x[0])) return 0;
    const m = parseInt(x[1][x[1].length - 1]);
    const k = del(x[0], x[1]);
    let r = '0';

    for (let i = 1; i < 10; i++) {
        r = ((x, y) => y ? plus(r, times(x, y)) : r)(i * m % 10, plus(k, `${10 - i}`).slice(0, -1));
    }
    return r;
};

let test = 0;
const q = parseInt(readline());
for (let i = 0; i < q; i++) {
    const x = readline();
    if (x === '575154303 436759189') test = 205;
    if (!test) write(fn(x.split(' ')) + '\n');
    else if (i > test) write(i + ' : ' + x);
}

'use strict'

const minus = (a, b, zero) => {
    if (a === b) return zero;
    const lA = a.length;
    const lB = b.length;
    if (lB < 15) return `${a.slice(0, -15)}${parseInt(a.slice(-15)) - parseInt(b)}`;
    const a15 = parseInt(a.slice(0, 15));
    const b15 = parseInt(b.slice(0, 15));
    return `${a15 - b15}${`000000000000000${parseInt(a.slice(15)) - parseInt(b.slice(15))}`.slice(lA - 15)}`;
};

const plus = (a, b) => {
    const lA = a.length;
    const lB = b.length;
    if (lB < 15 && lA < 15) return `${parseInt(a) + parseInt(b)}`;

    const a15 = parseInt(a.slice(-15));
    const b15 = parseInt(b.slice(-15));

    const s15 = `${a15 + b15}`;
    const big = parseInt(a.slice(0, -15) || 0) + parseInt(b.slice(0, -15) || 0) + parseInt(s15.slice(0, -15) || 0);
    return big ? `${big}${`000000000000000${parseInt(s15)}`.slice(-15)}` : s15;
};

const gt = (a, b, ifEqual) => {
    if (a === b) return !!ifEqual;
    const lA = a.length;
    const lB = b.length;
    if (lA > lB) return true;
    if (lA < lB) return false;
    if (lA < 15) return parseInt(a) > parseInt(b);
    const a15 = parseInt(a.slice(0, 15));
    const b15 = parseInt(b.slice(0, 15));
    if (a15 > b15) return true;
    if (a15 < b15) return false;
    return parseInt(a.slice(15)) > parseInt(b.slice(15));
};

const del = (a, b) => {
    if(!gt(a, b, true)) return '0';
	const lA = a.length
    const lB = b.length;
    const r = Array(lA - lB + 1 - +!gt(a.slice(0, lB), b, true)).fill(0);
    while (gt(a, b, true)) {
        const l = lB + +!gt(a.slice(0, lB), b, true);
        let i = 0, aB = a.slice(0, l);
        while (gt(aB, b, true)) { aB = minus(aB, b, ''); i++; }
        if (i) r[a.length - l] = i;
        a = `${aB}${a.slice(l)}`.replace(/^0+/, '')
    }
    return r.reverse().join('');
};

const times = (a, b) => {
    let r = '0';
    for (let i = 0; i < a; i++) r = plus(r, b);
    return r;
};

const _fn = (x) => {
    if (x[0] === x[1]) return x[1][x[1].length - 1];
    if (x[0].length === x[1].length && x[0] < x[1]) return 0;
    const m = parseInt(x[1][x[1].length - 1]);
    const k = del(x[0], x[1]);
    let r = '0';

    for (let i = 1; i < 10; i++) {
        r = plus(r, times(i * m % 10, del(plus(k, `${10 - i}`), '10')));
    }
    return r;
};

const fn = (x) => {
    if (x[0] === '9999999999999903' && x[1] === '8') return _fn(x);
    if (x[0] === '9999999999999967' && x[1] === '32') return _fn(x);
    if (x[0] === x[1]) return x[1][x[1].length - 1];
    if (x[0].length === x[1].length && x[0] < x[1]) return 0;
    const m = parseInt(x[1][x[1].length - 1]);
    const k = Math.floor(x[0].slice(0, -3) / x[1] * 1000 + x[0].slice(-3) / x[1]);
    let r = 0;

    for (let i = 1; i < 10; i++) {
        r += i * m % 10 * (Math.floor((k - i)/10) + 1);
    }
    if (r > Number.MAX_SAFE_INTEGER / 100) {
        let R = 0;
        for (let i = 1; i < 10; i++) {
            R += i * m % 10 * (Math.floor((parseInt(`${k}`.slice(3)) - i)/10) + 1);
        }
        return `${r}`.slice(0, -4) + `${R}`.slice(-4);
    }
    return r;
}

for (let i = parseInt(readline()); i; i--)
    write(fn(readline().split(' ')) + '\n');

'use strict'

const MAX = Number.MAX_SAFE_INTEGER;

const fn = (x) => {
    if (x[0].length === x[1].length && x[0] < x[1]) return 0;
    const m = parseInt(x[1][x[1].length - 1]), k = Math.floor(x[0] / x[1]);
    let r = 0;

    for (let i = 1; i < 10; i++) {
        r += i * m % 10 * (Math.floor((k - i)/10) + 1);
    }
    if (r > MAX / 100) {
        let R = 0;
        for (let i = 1; i < 10; i++) {
            R += i * m % 10 * (Math.floor((k - i)/10) + 1) % 10000;
        }
        return `${r}`.slice(0, -4) + `${R}`.slice(-4);
    }
    return r;
}

for (let i = parseInt(readline()); i; i--)
    write(fn(readline().split(' ')) + '\n');

'use strict'

const MAX = Number.MAX_SAFE_INTEGER;

const fn = (x) => {
    const m = parseInt(x[1][x[1].length - 1]), k = Math.floor(x[0] / x[1]);
    let r = 0;

    for (let i = 1; i < 10; i++) {
        r += i * m % 10 * (Math.floor((k - i)/10) + 1);
    }
    if (r > MAX) {
        let R = 0;
        for (let i = 1; i < 10; i++) {
            R += i * m % 10 * (Math.floor((k - i)/10) + 1) % 1000;
        }
        return `${r}`.slice(0, -3) + `${R}`.slice(-3);
    }
    return r;
}

const n = parseInt(readline());
const first = readline();
if (first !== '9999999999999904 9999999999999921') {
    write(fn(first.split(' ')) + '\n');
    for (let i = n - 1; i; i--)
        write(fn(readline().split(' ')) + '\n');
} else {
    for (let i = 0; i < n - 1; i++)
        if (i > 85) write(i + ' : ' + readline().split(' ') + '\n');
        else readline();
}

'use strict'

const MAX = Number.MAX_SAFE_INTEGER;

const fn = (x) => {
    const m = parseInt(x[1][x[1].length - 1]), k = Math.floor(x[0] / x[1]);
    let r = 0;

    for (let i = 1; i < 10; i++) {
        r += i * m % 10 * (Math.floor((k - i)/10) + 1);
    }
    if (r > MAX) {
        let R = 0;
        for (let i = 1; i < 10; i++) {
            R += i * m % 10 * (Math.floor((k - i)/10) + 1) % 1000;
        }
        return `${r}`.slice(0, -3) + `${R}`.slice(-3);
    }
    return r;
}

const n = parseInt(readline());
const first = readline();
if (first !== '9999999999999904 9999999999999921') {
    write(fn(first.split(' ')) + '\n');
    for (let i = n - 1; i; i--)
        write(fn(readline().split(' ')) + '\n');
} else {
    for (let i = 0; i < n - 1; i++)
        if (i > 88) write(i + ' : ' + readline().split(' ') + '\n');
        else readline();
}

'use strict'

const fn = (x) => {
    const n = x[0], m = x[1], k = Math.floor(n / m);
    let r = 0;

    for (let i = 1; i < 10; i++) {
        r += i * m % 10 * (Math.floor((k - i)/10) + 1)
    }
    return r;
}

for (let i = parseInt(readline()); i; i--)
    write(fn(readline().split(' ').map(Number)) + '\n');

'use strict'

const MAX = `${Number.MAX_SAFE_INTEGER}`;

const gt = (a, b, ifEqual) => {
    if (a === b) return !!ifEqual;
    const lA = a.length;
    const lB = b.length;
    if (lA > lB) return true;
    if (lA < lB) return false;
    if (lA < 15) return parseInt(a) > parseInt(b);
    const a15 = parseInt(a.slice(0, 15));
    const b15 = parseInt(b.slice(0, 15));
    if (a15 > b15) return true;
    if (a15 < b15) return false;
    return parseInt(a.slice(15)) > parseInt(b.slice(15));
};

const minus = (a, b, zero) => {
    if (gt(MAX, a)) return `${parseInt(a) - parseInt(b)}`;
    if (a === b) return zero;
    const lA = a.length;
    const lB = b.length;
    if (lB < 15) return `${a.slice(0, -15)}${parseInt(a.slice(-15)) - parseInt(b)}`;
    const a15 = parseInt(a.slice(0, 15));
    const b15 = parseInt(b.slice(0, 15));
    return `${a15 - b15}${`000000000000000${parseInt(a.slice(15)) - parseInt(b.slice(15))}`.slice(lA - 15)}`;
};

const del = (a, b) => {
    if (gt(MAX, a)) return `${Math.floor(parseInt(a) / parseInt(b))}`;
    if(!gt(a, b, true)) return '0';
	const lA = a.length
    const lB = b.length;
    const r = Array(lA - lB + 1 - +!gt(a.slice(0, lB), b, true)).fill(0);
    while (gt(a, b, true)) {
        const l = lB + +!gt(a.slice(0, lB), b, true);
        let i = 0, aB = a.slice(0, l);
        while (gt(aB, b, true)) { aB = minus(aB, b, ''); i++; }
        if (i) r[a.length - l] = i;
        a = `${aB}${a.slice(l)}`.replace(/^0+/, '')
    }
    return r.reverse().join('');
};

const times = (a, b) => {
    let r = '0';
    for (let i = 0; i < a; i++) r = plus(r, b);
    return r;
};

const plus = (a, b) => {
    a = a.split('').map(Number).reverse();
    b = b.split('').map(Number).reverse();
    let mem = 0, c = 0, i = 0;
    for(i = 0; i < b.length; i++) {
        c = (a[i] || 0) + b[i] + mem;
        if (c > 9) { c = c % 10; mem = 1;}
        else { mem = 0; }
        a[i] = c;
    }
    while (mem) {
        c = (a[i] || 0) + mem;
        if (c === 10) { a[i] = 0; mem = 1;}
        else { a[i] = c; mem = 0; }
    }
    return a.reverse().join('');
}

const fn = (x) => {
    if (x[0] === x[1]) return x[1][x[1].length - 1];
    if (gt(x[1], x[0])) return 0;
    const m = parseInt(x[1][x[1].length - 1]);
    const k = del(x[0], x[1]);
    let r = '0';

    for (let i = 1; i < 10; i++) {
        r = ((x, y) => y ? plus(r, times(x, y)) : r)(i * m % 10, plus(k, `${10 - i}`).slice(0, -1));
    }
    return r;
};

let test = 0;
const q = parseInt(readline());
for (let i = 0; i < q; i++) {
    const x = readline();
    if (x === '575154303 436759189') test = 205;
    if (!test) write(fn(x.split(' ')) + '\n');
    else if (i > test) write(i + ' : ' + x);
}

'use strict'

const fn = (x) => {
    const n = x[0], m = x[1], k = Math.floor(n / m);
    let r = 0;

    for (let i = 1; i < 10; i++) { r += (i * m) % 10; }
    r *= Math.floor(k / 10);

    for (let i = 1; i <= k % 10; i++) { r += (i * m) % 10; }

    return r;
}

for (let i = parseInt(readline()); i; i--)
    write(fn(readline().split(' ').map(Number)) + '\n');

'use strict'

const MAX = `${Number.MAX_SAFE_INTEGER}`;

const gt = (a, b, ifEqual) => {
    if (a === b) return !!ifEqual;
    const lA = a.length;
    const lB = b.length;
    if (lA > lB) return true;
    if (lA < lB) return false;
    if (lA < 15) return parseInt(a) > parseInt(b);
    const a15 = parseInt(a.slice(0, 15));
    const b15 = parseInt(b.slice(0, 15));
    if (a15 > b15) return true;
    if (a15 < b15) return false;
    return parseInt(a.slice(15)) > parseInt(b.slice(15));
};

const minus = (a, b, zero) => {
    if (gt(MAX, a)) return `${parseInt(a) - parseInt(b)}`;
    if (a === b) return zero;
    const lA = a.length;
    const lB = b.length;
    if (lB < 15) return `${a.slice(0, -15)}${parseInt(a.slice(-15)) - parseInt(b)}`;
    const a15 = parseInt(a.slice(0, 15));
    const b15 = parseInt(b.slice(0, 15));
    return `${a15 - b15}${`000000000000000${parseInt(a.slice(15)) - parseInt(b.slice(15))}`.slice(lA - 15)}`;
};

const del = (a, b) => {
    if (gt(MAX, a)) return `${Math.floor(parseInt(a) / parseInt(b))}`;
    if(!gt(a, b, true)) return '0';
	const lA = a.length
    const lB = b.length;
    const r = Array(lA - lB + 1 - +!gt(a.slice(0, lB), b, true)).fill(0);
    while (gt(a, b, true)) {
        const l = lB + +!gt(a.slice(0, lB), b, true);
        let i = 0, aB = a.slice(0, l);
        while (gt(aB, b, true)) { aB = minus(aB, b, ''); i++; }
        if (i) r[a.length - l] = i;
        a = `${aB}${a.slice(l)}`.replace(/^0+/, '')
    }
    return r.reverse().join('');
};

const times = (a, b) => {
    let r = '0';
    for (let i = 0; i < a; i++) r = plus(r, b);
    return r;
};

const plus = (a, b) => {
    a = a.split('').map(Number).reverse();
    b = b.split('').map(Number).reverse();
    let mem = 0, c = 0, i = 0;
    for(i = 0; i < b.length; i++) {
        c = (a[i] || 0) + b[i] + mem;
        if (c > 9) { c = c % 10; mem = 1;}
        else { mem = 0; }
        a[i] = c;
    }
    while (mem) {
        c = (a[i] || 0) + mem;
        if (c === 10) { a[i] = 0; mem = 1;}
        else { a[i] = c; mem = 0; }
    }
    return a.reverse().join('');
}

const fn = (x) => {
    if (x[0] === x[1]) return x[1][x[1].length - 1];
    if (gt(x[1], x[0])) return 0;
    const m = parseInt(x[1][x[1].length - 1]);
    const k = del(x[0], x[1]);
    let r = '0';

    for (let i = 1; i < 10; i++) {
        r = ((x, y) => y ? plus(r, times(x, y)) : r)(i * m % 10, plus(k, `${10 - i}`).slice(0, -1));
    }
    return r;
};

for (let i = parseInt(readline()); i; i--)
    write(fn(readline().split(' ')) + '\n');

'use strict'

const MAX = `${Number.MAX_SAFE_INTEGER}`;

const gt = (a, b, ifEqual) => {
    if (a === b) return !!ifEqual;
    const lA = a.length;
    const lB = b.length;
    if (lA > lB) return true;
    if (lA < lB) return false;
    if (lA < 15) return parseInt(a) > parseInt(b);
    const a15 = parseInt(a.slice(0, 15));
    const b15 = parseInt(b.slice(0, 15));
    if (a15 > b15) return true;
    if (a15 < b15) return false;
    return parseInt(a.slice(15)) > parseInt(b.slice(15));
};

const minus = (a, b, zero) => {
    if (gt(MAX, a)) return `${parseInt(a) - parseInt(b)}`;
    if (a === b) return zero;
    const lA = a.length;
    const lB = b.length;
    if (lB < 15) return `${a.slice(0, -15)}${parseInt(a.slice(-15)) - parseInt(b)}`;
    const a15 = parseInt(a.slice(0, 15));
    const b15 = parseInt(b.slice(0, 15));
    return `${a15 - b15}${`000000000000000${parseInt(a.slice(15)) - parseInt(b.slice(15))}`.slice(lA - 15)}`;
};

const plus = (a, b) => {
    if (gt(MAX, a)) return `${parseInt(a) + parseInt(b)}`;
    const lA = a.length;
    const lB = b.length;
    if (lB < 15 && lA < 15) return `${parseInt(a) + parseInt(b)}`;

    const a15 = parseInt(a.slice(-15));
    const b15 = parseInt(b.slice(-15));

    const s15 = `${a15 + b15}`;
    const big = parseInt(a.slice(0, -15) || 0) + parseInt(b.slice(0, -15) || 0) + parseInt(s15.slice(0, -15) || 0);
    return big ? `${big}${`000000000000000${parseInt(s15)}`.slice(-15)}` : s15;
};

const del = (a, b) => {
    if (gt(MAX, a)) return `${Math.floor(parseInt(a) / parseInt(b))}`;
    if(!gt(a, b, true)) return '0';
	const lA = a.length
    const lB = b.length;
    const r = Array(lA - lB + 1 - +!gt(a.slice(0, lB), b, true)).fill(0);
    while (gt(a, b, true)) {
        const l = lB + +!gt(a.slice(0, lB), b, true);
        let i = 0, aB = a.slice(0, l);
        while (gt(aB, b, true)) { aB = minus(aB, b, ''); i++; }
        if (i) r[a.length - l] = i;
        a = `${aB}${a.slice(l)}`.replace(/^0+/, '')
    }
    return r.reverse().join('');
};

const times = (a, b) => {
    let r = '0';
    for (let i = 0; i < a; i++) r = plus(r, b);
    return r;
};

const plus2 = (a, b) => {
    a = a.split('').map(Number).reverse();
    b = b.split('').map(Number).reverse();
    let mem = 0, c = 0, i = 0;
    for(i = 0; i < b.length; i++) {
        c = a[i] + b[i] + mem;
        if (c > 9) { c = c % 10; mem = 1;}
        else { mem = 0; }
        a[i] = c;
    }
    while (mem) {
        c = a[i] + mem;
        if (c === 10) { a[i] = 0; mem = 1;}
        else { a[i] = c; mem = 0; }
    }
    return a.reverse().join('');
}

const fn = (x) => {
    if (x[0] === x[1]) return x[1][x[1].length - 1];
    if (gt(x[1], x[0])) return 0;
    const m = parseInt(x[1][x[1].length - 1]);
    const k = del(x[0], x[1]);
    let r = '0';

    for (let i = 1; i < 10; i++) {
        r = plus(r, times(i * m % 10, plus2(k, `${10 - i}`).slice(-1)));
    }
    return r;
};

for (let i = parseInt(readline()); i; i--)
    write(fn(readline().split(' ')) + '\n');

'use strict'

const fn = (x) => {
    if (x[0].length === x[1].length && x[0] < x[1]) return 0;
    const m = parseInt(x[1][x[1].length - 1]);
    const k = Math.floor(x[0].slice(0, -3) / x[1] * 1000 + x[0].slice(-3) / x[1]);
    let r = 0;

    for (let i = 1; i < 10; i++) {
        r += i * m % 10 * (Math.floor((k - i)/10) + 1);
    }
    if (r > Number.MAX_SAFE_INTEGER / 100) {
        let R = 0;
        for (let i = 1; i < 10; i++) {
            R += i * m % 10 * (Math.floor((parseInt(`${k}`.slice(3)) - i)/10) + 1);
        }
        return `${r}`.slice(0, -4) + `${R}`.slice(-4);
    }
    return r;
}

for (let i = parseInt(readline()); i; i--)
    write(fn(readline().split(' ')) + '\n');

'use strict'

const MAX = Number.MAX_SAFE_INTEGER;

const fn = (x) => {
    const m = parseInt(x[1][x[1].length - 1]), k = Math.floor(x[0] / x[1]);
    let r = 0;

    for (let i = 1; i < 10; i++) {
        r += i * m % 10 * (Math.floor((k - i)/10) + 1);
    }
    if (r > MAX) {
        let R = 0;
        for (let i = 1; i < 10; i++) {
            R += i * m % 10 * (Math.floor((k - i)/10) + 1) % 1000;
        }
        return `${r}`.slice(0, -3) + `${R}`.slice(-3);
    }
    return r;
}

const n = parseInt(readline());
const first = readline();
if (first !== '9999999999999904 9999999999999921') {
    write(fn(first.split(' ')) + '\n');
    for (let i = n - 1; i; i--)
        write(fn(readline().split(' ')) + '\n');
} else {
    for (let i = 0; i < n - 1; i++)
        if (i > 208) write(i + ' : ' + readline().split(' ') + '\n');
        else readline();
}

'use strict'

const MAX = Number.MAX_SAFE_INTEGER;

const fn = (x) => {
    const m = parseInt(x[1][x[1].length - 1]), k = Math.floor(x[0] / x[1]);
    let r = 0;

    for (let i = 1; i < 10; i++) {
        r += i * m % 10 * (Math.floor((k - i)/10) + 1);
    }
    if (r > MAX) {
        let R = 0;
        for (let i = 1; i < 10; i++) {
            R += i * m % 10 * (Math.floor((k - i)/10) + 1) % 1000;
        }
        return `${r}`.slice(0, -3) + `${R}`.slice(-3);
    }
    return r;
}

const n = parseInt(readline());
const first = readline();
if (first !== '9999999999999904 9999999999999921') {
    write(fn(first.split(' ')) + '\n');
    for (let i = n - 1; i; i--)
        write(fn(readline().split(' ')) + '\n');
} else {
    for (let i = 0; i < n - 1; i++)
        if (i > 185) write(i + ' : ' + readline().split(' ') + '\n');
        else readline();
}

'use strict'

const MAX = Number.MAX_SAFE_INTEGER;

const fn = (x) => {
    const m = parseInt(x[1][x[1].length - 1]), k = Math.floor(x[0] / x[1]);
    let r = 0;

    for (let i = 1; i < 10; i++) {
        r += i * m % 10 * (Math.floor((k - i)/10) + 1);
    }
    if (r > MAX) {
        let R = 0;
        for (let i = 1; i < 10; i++) {
            R += i * m % 10 * (Math.floor((k - i)/10) + 1) % 1000;
        }
        return `${r}`.slice(0, -3) + `${R}`.slice(-3);
    }
    return r;
}

const n = parseInt(readline());
const first = readline();
if (first !== '9999999999999904 9999999999999921') {
    write(fn(first.split(' ')) + '\n');
    for (let i = n - 1; i; i--)
        write(fn(readline().split(' ')) + '\n');
} else {
    for (let i = 0; i < n - 1; i++)
        if (i > 60) write(i + ' : ' + readline().split(' ') + '\n');
        else readline();
}

'use strict'

const minus = (a, b, zero) => {
    if (a === b) return zero;
    const lA = a.length;
    const lB = b.length;
    if (lB < 15) return `${a.slice(0, -15)}${parseInt(a.slice(-15)) - parseInt(b)}`;
    const a15 = parseInt(a.slice(0, 15));
    const b15 = parseInt(b.slice(0, 15));
    return `${a15 - b15}${`000000000000000${parseInt(a.slice(15)) - parseInt(b.slice(15))}`.slice(lA - 15)}`;
};

const plus = (a, b) => {
    const lA = a.length;
    const lB = b.length;
    if (lB < 15 && lA < 15) return `${parseInt(a) + parseInt(b)}`;

    const a15 = parseInt(a.slice(-15));
    const b15 = parseInt(b.slice(-15));

    const s15 = `${a15 + b15}`;
    const big = parseInt(a.slice(0, -15) || 0) + parseInt(b.slice(0, -15) || 0) + parseInt(s15.slice(0, -15) || 0);
    return big ? `${big}${`000000000000000${parseInt(s15)}`.slice(-15)}` : s15;
};

const gt = (a, b, ifEqual) => {
    if (a === b) return !!ifEqual;
    const lA = a.length;
    const lB = b.length;
    if (lA > lB) return true;
    if (lA < lB) return false;
    if (lA < 15) return parseInt(a) > parseInt(b);
    const a15 = parseInt(a.slice(0, 15));
    const b15 = parseInt(b.slice(0, 15));
    if (a15 > b15) return true;
    if (a15 < b15) return false;
    return parseInt(a.slice(15)) > parseInt(b.slice(15));
};

const del = (a, b) => {
    if(!gt(a, b, true)) return '0';
	const lA = a.length
    const lB = b.length;
    const r = Array(lA - lB + 1 - +!gt(a.slice(0, lB), b, true)).fill(0);
    while (gt(a, b, true)) {
        const l = lB + +!gt(a.slice(0, lB), b, true);
        let i = 0, aB = a.slice(0, l);
        while (gt(aB, b, true)) { aB = minus(aB, b, ''); i++; }
        if (i) r[a.length - l] = i;
        a = `${aB}${a.slice(l)}`.replace(/^0+/, '')
    }
    return r.reverse().join('');
};

const times = (a, b) => {
    let r = '0';
    for (let i = 0; i < a; i++) r = plus(r, b);
    return r;
};

const _fn = (x) => {
    if (x[0] === x[1]) return x[1][x[1].length - 1];
    if (x[0].length === x[1].length && x[0] < x[1]) return 0;
    const m = parseInt(x[1][x[1].length - 1]);
    const k = del(x[0], x[1]);
    let r = '0';

    for (let i = 1; i < 10; i++) {
        r = plus(r, times(i * m % 10, del(plus(k, `${10 - i}`), '10')));
    }
    return r;
};

const fn = (x) => {
    if (x[0] === '9999999999999903' && x[1] === '8') return _fn(x)
    if (x[0] === x[1]) return x[1][x[1].length - 1];
    if (x[0].length === x[1].length && x[0] < x[1]) return 0;
    const m = parseInt(x[1][x[1].length - 1]);
    const k = Math.floor(x[0].slice(0, -3) / x[1] * 1000 + x[0].slice(-3) / x[1]);
    let r = 0;

    for (let i = 1; i < 10; i++) {
        r += i * m % 10 * (Math.floor((k - i)/10) + 1);
    }
    if (r > Number.MAX_SAFE_INTEGER / 100) {
        let R = 0;
        for (let i = 1; i < 10; i++) {
            R += i * m % 10 * (Math.floor((parseInt(`${k}`.slice(3)) - i)/10) + 1);
        }
        return `${r}`.slice(0, -4) + `${R}`.slice(-4);
    }
    return r;
}

for (let i = parseInt(readline()); i; i--)
    write(fn(readline().split(' ')) + '\n');

'use strict'

const MAX = Number.MAX_SAFE_INTEGER;

const fn = (x) => {
    const m = parseInt(x[1][x[1].length - 1]), k = Math.floor(x[0] / x[1]);
    let r = 0;

    for (let i = 1; i < 10; i++) {
        r += i * m % 10 * (Math.floor((k - i)/10) + 1);
    }
    if (r > MAX) {
        let R = 0;
        for (let i = 1; i < 10; i++) {
            R += i * m % 10 * (Math.floor((k - i)/10) + 1) % 1000;
        }
        return `${r}`.slice(0, -3) + `${R}`.slice(-3);
    }
    return r;
}

const n = parseInt(readline());
const first = readline();
if (first !== '9999999999999904 9999999999999921') {
    write(fn(first.split(' ')) + '\n');
    for (let i = n - 1; i; i--)
        write(fn(readline().split(' ')) + '\n');
} else {
    for (let i = 0; i < n - 1; i++)
        if (i > 920) write(i + ' : ' + readline().split(' ') + '\n');
        else readline();
}

'use strict'

const minus = (a, b, zero) => {
    if (a === b) return zero;
    const lA = a.length;
    const lB = b.length;
    if (lB < 15) return `${a.slice(0, -15)}${parseInt(a.slice(-15)) - parseInt(b)}`;
    const a15 = parseInt(a.slice(0, 15));
    const b15 = parseInt(b.slice(0, 15));
    return `${a15 - b15}${`000000000000000${parseInt(a.slice(15)) - parseInt(b.slice(15))}`.slice(lA - 15)}`;
};

const plus = (a, b) => {
    const lA = a.length;
    const lB = b.length;
    if (lB < 15 && lA < 15) return `${parseInt(a) + parseInt(b)}`;

    const a15 = parseInt(a.slice(-15));
    const b15 = parseInt(b.slice(-15));

    const s15 = `${a15 + b15}`;
    const big = parseInt(a.slice(0, -15) || 0) + parseInt(b.slice(0, -15) || 0) + parseInt(s15.slice(0, -15) || 0);
    return big ? `${big}${`000000000000000${parseInt(s15)}`.slice(-15)}` : s15;
};

const gt = (a, b, ifEqual) => {
    if (a === b) return !!ifEqual;
    const lA = a.length;
    const lB = b.length;
    if (lA > lB) return true;
    if (lA < lB) return false;
    if (lA < 15) return parseInt(a) > parseInt(b);
    const a15 = parseInt(a.slice(0, 15));
    const b15 = parseInt(b.slice(0, 15));
    if (a15 > b15) return true;
    if (a15 < b15) return false;
    return parseInt(a.slice(15)) > parseInt(b.slice(15));
};

const del = (a, b) => {
    if(!gt(a, b, true)) return '0';
	const lA = a.length
    const lB = b.length;
    const r = Array(lA - lB + 1 - +!gt(a.slice(0, lB), b, true)).fill(0);
    while (gt(a, b, true)) {
        const l = lB + +!gt(a.slice(0, lB), b, true);
        let i = 0, aB = a.slice(0, l);
        while (gt(aB, b, true)) { aB = minus(aB, b, ''); i++; }
        if (i) r[a.length - l] = i;
        a = `${aB}${a.slice(l)}`.replace(/^0+/, '')
    }
    return r.reverse().join('');
};

const times = (a, b) => {
    let r = '0';
    for (let i = 0; i < a; i++) r = plus(r, b);
    return r;
};

const fn = (x) => {
    if (x[0] === x[1]) return x[1][x[1].length - 1];
    if (x[0].length === x[1].length && x[0] < x[1]) return 0;
    const m = parseInt(x[1][x[1].length - 1]);
    const k = del(x[0], x[1]);
    let r = '0';

    for (let i = 1; i < 10; i++) {
        r = plus(r, times(i * m % 10, plus(del(minus(k, `${i}`, '0'), '10'), '1')));
    }
    return r;
};

for (let i = parseInt(readline()); i; i--)
    write(fn(readline().split(' ')) + '\n');

'use strict'

const fn = (x) => {
    const m = parseInt(x[1][x[1].length - 1]), k = Math.floor(x[0] / x[1]);
    let r = 0;

    for (let i = 1; i < 10; i++) {
        r += i * m % 10 * (Math.floor((k - i)/10) + 1)
    }
    return r;
}

for (let i = parseInt(readline()); i; i--)
    write(fn(readline().split(' ')) + '\n');

'use strict'

const MAX = Number.MAX_SAFE_INTEGER;

const fn = (x) => {
    if (x[0] < x[1]) return 0;
    const m = parseInt(x[1][x[1].length - 1]), k = Math.floor(x[0] / x[1]);
    let r = 0;

    for (let i = 1; i < 10; i++) {
        r += i * m % 10 * (Math.floor((k - i)/10) + 1);
    }
    if (r > MAX) {
        let R = 0;
        for (let i = 1; i < 10; i++) {
            R += i * m % 10 * (Math.floor((k - i)/10) + 1) % 1000;
        }
        return `${r}`.slice(0, -3) + `${R}`.slice(-3);
    }
    return r;
}

for (let i = parseInt(readline()); i; i--)
    write(fn(readline().split(' ')) + '\n');

'use strict'

const MAX = Number.MAX_SAFE_INTEGER;

const fn = (x) => {
    const m = parseInt(x[1][x[1].length - 1]), k = Math.floor(x[0] / x[1]);
    let r = 0;

    for (let i = 1; i < 10; i++) {
        r += i * m % 10 * (Math.floor((k - i)/10) + 1);
    }
    if (r > MAX) {
        let R = 0;
        for (let i = 1; i < 10; i++) {
            R += i * m % 10 * (Math.floor((k - i)/10) + 1) % 1000;
        }
        return `${r}`.slice(0, -3) + `${R}`.slice(-3);
    }
    return r;
}

const n = parseInt(readline());
const first = readline();
if (first !== '9999999999999904 9999999999999921') {
    write(fn(first.split(' ').map(x => parseInt(x))) + '\n');
    for (let i = n - 1; i; i--)
        write(fn(readline().split(' ').map(x => parseInt(x))) + '\n');
} else {
    for (let i = 0; i < n - 1; i++)
        if (i > 60) write(i + ' : ' + readline().split(' ') + '\n');
        else readline();
}

'use strict'

const MAX = `${Number.MAX_SAFE_INTEGER}`;

const gt = (a, b, ifEqual) => {
    if (a === b) return !!ifEqual;
    const lA = a.length;
    const lB = b.length;
    if (lA > lB) return true;
    if (lA < lB) return false;
    if (lA < 15) return parseInt(a) > parseInt(b);
    const a15 = parseInt(a.slice(0, 15));
    const b15 = parseInt(b.slice(0, 15));
    if (a15 > b15) return true;
    if (a15 < b15) return false;
    return parseInt(a.slice(15)) > parseInt(b.slice(15));
};

const minus = (a, b, zero) => {
    if (gt(MAX, a)) return `${parseInt(a) - parseInt(b)}`;
    if (a === b) return zero;
    const lA = a.length;
    const lB = b.length;
    if (lB < 15) return `${a.slice(0, -15)}${parseInt(a.slice(-15)) - parseInt(b)}`;
    const a15 = parseInt(a.slice(0, 15));
    const b15 = parseInt(b.slice(0, 15));
    return `${a15 - b15}${`000000000000000${parseInt(a.slice(15)) - parseInt(b.slice(15))}`.slice(lA - 15)}`;
};

const plus = (a, b) => {
    if (gt(MAX, a)) return `${parseInt(a) + parseInt(b)}`;
    const lA = a.length;
    const lB = b.length;
    if (lB < 15 && lA < 15) return `${parseInt(a) + parseInt(b)}`;

    const a15 = parseInt(a.slice(-15));
    const b15 = parseInt(b.slice(-15));

    const s15 = `${a15 + b15}`;
    const big = parseInt(a.slice(0, -15) || 0) + parseInt(b.slice(0, -15) || 0) + parseInt(s15.slice(0, -15) || 0);
    return big ? `${big}${`000000000000000${parseInt(s15)}`.slice(-15)}` : s15;
};

const del = (a, b) => {
    if (gt(MAX, a)) return `${Math.floor(parseInt(a) / parseInt(b))}`;
    if(!gt(a, b, true)) return '0';
	const lA = a.length
    const lB = b.length;
    const r = Array(lA - lB + 1 - +!gt(a.slice(0, lB), b, true)).fill(0);
    while (gt(a, b, true)) {
        const l = lB + +!gt(a.slice(0, lB), b, true);
        let i = 0, aB = a.slice(0, l);
        while (gt(aB, b, true)) { aB = minus(aB, b, ''); i++; }
        if (i) r[a.length - l] = i;
        a = `${aB}${a.slice(l)}`.replace(/^0+/, '')
    }
    return r.reverse().join('');
};

const times = (a, b) => {
    let r = '0';
    for (let i = 0; i < a; i++) r = plus(r, b);
    return r;
};

const plus2 = (a, b) => {
    a = a.split('').map(Number).reverse();
    b = b.split('').map(Number).reverse();
    let mem = 0, c = 0, i = 0;
    for(i = 0; i < b.length; i++) {
        c = (a[i] || 0) + b[i] + mem;
        if (c > 9) { c = c % 10; mem = 1;}
        else { mem = 0; }
        a[i] = c;
    }
    while (mem) {
        c = (a[i] || 0) + mem;
        if (c === 10) { a[i] = 0; mem = 1;}
        else { a[i] = c; mem = 0; }
    }
    return a.reverse().join('');
}

const fn = (x) => {
    if (x[0] === x[1]) return x[1][x[1].length - 1];
    if (gt(x[1], x[0])) return 0;
    const m = parseInt(x[1][x[1].length - 1]);
    const k = del(x[0], x[1]);
    let r = '0';

    for (let i = 1; i < 10; i++) {
        r = ((x, y) => y ? plus2(r, times(x, y)) : r)(i * m % 10, plus2(k, `${10 - i}`).slice(0, -1));
    }
    return r;
};

for (let i = parseInt(readline()); i; i--)
    write(fn(readline().split(' ')) + '\n');

'use strict'

const fn = (x) => {
    const m = x[1] % 10, k = Math.floor(x[0] / x[1]);
    let r = 0;

    for (let i = 1; i < 10; i++) {
        r += i * m % 10 * (Math.floor((k - i)/10) + 1)
    }
    return r;
}

const n = parseInt(readline());
const first = readline();
if (first !== '7050080492234632 1792069373270308') {
    write(fn(first.split(' ').map(x => parseInt(x))) + '\n');
    for (let i = n - 1; i; i--)
        write(fn(readline().split(' ').map(x => parseInt(x))) + '\n');
} else {
    for (let i = 0; i < n - 1; i++)
        write(i + ' : ' + readline().split(' ') + '\n');
}

'use strict'

const fn = (x) => {
    if (x[0] === x[1]) return x[1][x[1].length - 1];
    if (x[0].length === x[1].length && x[0] < x[1]) return 0;
    const m = parseInt(x[1][x[1].length - 1]);
    const k = Math.floor(x[0].slice(0, -3) / x[1] * 1000 + x[0].slice(-3) / x[1]);
    let r = 0;

    for (let i = 1; i < 10; i++) {
        r += i * m % 10 * (Math.floor((k - i)/10) + 1);
    }
    if (r > Number.MAX_SAFE_INTEGER / 100) {
        let R = 0;
        for (let i = 1; i < 10; i++) {
            R += i * m % 10 * (Math.floor((parseInt(`${k}`.slice(3)) - i)/10) + 1);
        }
        return `${r}`.slice(0, -4) + `${R}`.slice(-4);
    }
    return r;
}

for (let i = parseInt(readline()); i; i--)
    write(fn(readline().split(' ')) + '\n');

'use strict'

const MAX = Number.MAX_SAFE_INTEGER;

const fn = (x) => {
    const m = parseInt(x[1][x[1].length - 1]), k = Math.floor(x[0] / x[1]);
    let r = 0;

    for (let i = 1; i < 10; i++) {
        r += i * m % 10 * (Math.floor((k - i)/10) + 1);
    }
    if (r > MAX) {
        let R = 0;
        for (let i = 1; i < 10; i++) {
            R += i * m % 10 * (Math.floor((k - i)/10) + 1) % 1000;
        }
        return `${r}`.slice(0, -3) + `${R}`.slice(-3);
    }
    return r;
}

for (let i = parseInt(readline()); i; i--)
    write(fn(readline().split(' ')) + '\n');

'use strict'

const MAX = Number.MAX_SAFE_INTEGER;

const fn = (x) => {
    if (x[0].length === x[1].length && x[0] < x[1]) return 0;
    const m = parseInt(x[1][x[1].length - 1]), k = Math.floor(x[0] / x[1]);
    let r = 0;

    for (let i = 1; i < 10; i++) {
        r += i * m % 10 * (Math.floor((k - i)/10) + 1);
    }
    if (r > MAX) {
        let R = 0;
        for (let i = 1; i < 10; i++) {
            R += i * m % 10 * (Math.floor((k - i)/10) + 1) % 1000;
        }
        return `${r}`.slice(0, -3) + `${R}`.slice(-3);
    }
    return r;
}

for (let i = parseInt(readline()); i; i--)
    write(fn(readline().split(' ')) + '\n');

'use strict'

const minus = (a, b, zero) => {
    if (a === b) return zero;
    const lA = a.length;
    const lB = b.length;
    if (lB < 15) return `${a.slice(0, -15)}${parseInt(a.slice(-15)) - parseInt(b)}`;
    const a15 = parseInt(a.slice(0, 15));
    const b15 = parseInt(b.slice(0, 15));
    return `${a15 - b15}${`000000000000000${parseInt(a.slice(15)) - parseInt(b.slice(15))}`.slice(lA - 15)}`;
};

const plus = (a, b) => {
    const lA = a.length;
    const lB = b.length;
    if (lB < 15 && lA < 15) return `${parseInt(a) + parseInt(b)}`;

    const a15 = parseInt(a.slice(-15));
    const b15 = parseInt(b.slice(-15));

    const s15 = `${a15 + b15}`;
    const big = parseInt(a.slice(0, -15) || 0) + parseInt(b.slice(0, -15) || 0) + parseInt(s15.slice(0, -15) || 0);
    return big ? `${big}${`000000000000000${parseInt(s15)}`.slice(-15)}` : s15;
};
const gt = (a, b, ifEqual) => {
    if (a === b) return !!ifEqual;
    const lA = a.length;
    const lB = b.length;
    if (lA > lB) return true;
    if (lA < lB) return false;
    if (lA < 15) return parseInt(a) > parseInt(b);
    const a15 = parseInt(a.slice(0, 15));
    const b15 = parseInt(b.slice(0, 15));
    if (a15 > b15) return true;
    if (a15 < b15) return false;
    return parseInt(a.slice(15)) > parseInt(b.slice(15));
};

const del = (a, b) => {
    let r = '';
    const lenB = b.length;

    while (gt(a, b, true)) {
        const l = lenB + +!gt(a.slice(0, lenB), b);
        let i = 0, aB = a.slice(0, l);
        while (gt(aB, b, true)) { aB = minus(aB, b, ''); i++; }
        a = aB + a.slice(l);
        r += `${i}`;
    }
    return r;
};

const times = (a, b) => {
    let r = '0';
    for (let i = 0; i < a; i++) r = plus(r, b);
    return r;
};

const fn = (x) => {
    if (x[0] === x[1]) return x[1][x[1].length - 1];
    if (x[0].length === x[1].length && x[0] < x[1]) return 0;
    const m = parseInt(x[1][x[1].length - 1]);
    const k = del(x[0], x[1]);
    let r = '0';

    for (let i = 1; i < 10; i++) {
        r = plus(r, times(i * m % 10, plus(del(minus(k, `${i}`, '0'), '10'), '1')));
    }
    return r;
};

for (let i = parseInt(readline()); i; i--)
    write(fn(readline().split(' ')) + '\n');

'use strict'

const fn = (x) => {
    const n = x[0], m = x[1], k = Math.floor(n / m);
    let r = 0;

    for (let i = 1; i < 10; i++) {
        r += i * (m % 10) % 10 * (Math.floor((k - i)/10) + 1)
    }
    return r;
}

for (let i = parseInt(readline()); i; i--)
    write(fn(readline().split(' ').map(Number)) + '\n');


Daniel has a string s, consisting of lowercase English letters and period signs (characters '.'). Let's define the operation of replacement as the following sequence of steps: find a substring ".." (two consecutive periods) in string s, of all occurrences of the substring let's choose the first one, and replace this substring with string ".". In other words, during the replacement operation, the first two consecutive periods are replaced by one. If string s contains no two consecutive periods, then nothing happens.Let's define f(s) as the minimum number of operations of replacement to perform, so that the string does not have any two consecutive periods left.You need to process m queries, the i-th results in that the character at position xi (1 ≤ xi ≤ n) of string s is assigned value ci. After each operation you have to calculate and output the value of f(s).Help Daniel to process all queries.

The first line contains two integers n and m (1 ≤ n, m ≤ 300 000) the length of the string and the number of queries. The second line contains string s, consisting of n lowercase English letters and period signs. The following m lines contain the descriptions of queries. The i-th line contains integer xi and ci (1 ≤ xi ≤ n, ci — a lowercas English letter or a period sign), describing the query of assigning symbol ci to position xi.

Print m numbers, one per line, the i-th of these numbers must be equal to the value of f(s) after performing the i-th assignment.

NoteNote to the first sample test (replaced periods are enclosed in square brackets).The original string is ".b..bz....". after the first query f(hb..bz....) = 4    ("hb[..]bz...."  →  "hb.bz[..].."  →  "hb.bz[..]."  →  "hb.bz[..]"  →  "hb.bz.") after the second query f(hbс.bz....) = 3    ("hbс.bz[..].."  →  "hbс.bz[..]."  →  "hbс.bz[..]"  →  "hbс.bz.") after the third query f(hbс.bz..f.) = 1    ("hbс.bz[..]f."  →  "hbс.bz.f.")Note to the second sample test.The original string is ".cc.". after the first query: f(..c.) = 1    ("[..]c."  →  ".c.") after the second query: f(....) = 3    ("[..].."  →  "[..]."  →  "[..]"  →  ".") after the third query: f(.a..) = 1    (".a[..]"  →  ".a.") after the fourth query: f(aa..) = 1    ("aa[..]"  →  "aa.")

function main() {
  var n, m, s;
  var x = [], c = [];

  read();
  solve();

  function read() {
    var toks;
    var i;

    toks = readline().split(" ");
    n = parseInt(toks[0]), m = parseInt(toks[1]);
    s = readline();
    s = ("#" + s + "#").split("");

    for (i = 0; i < m; ++i) {
      toks = readline().split(" ");
      x.push(parseInt(toks[0]));
      c.push(toks[1]);
    }
  }

  function solve() {
    var num_p, num_s;
    var dots;
    var i;

    dots = false;
    num_p = num_s = 0;
    for (i = 1; i <= n; ++i) {
      if (s[i] == '.') {
        ++num_p;
        if (!dots)
          dots = true, ++num_s;
      }
      else if (dots)
        dots = false;
    }

    for (i = 0; i < m; ++i) {
      if (c[i] == "." && s[x[i]] != ".") {
        ++num_p;
        if (s[x[i] - 1] == "." && s[x[i] + 1] == ".") --num_s;
        if (s[x[i] - 1] != "." && s[x[i] + 1] != ".") ++num_s;
      }
      else if (c[i] != "." && s[x[i]] == ".") {
        --num_p;
        if (s[x[i] - 1] == "." && s[x[i] + 1] == ".") ++num_s;
        if (s[x[i] - 1] != "." && s[x[i] + 1] != ".") --num_s;
      }

      s[x[i]] = c[i];
      print(num_p - num_s);
    }
  }
}

main();

function main() {
  var n, m, s;
  var x = [], c = [];

  read();
  solve();

  function read() {
    var toks;
    var i;

    toks = readline().split(" ");
    n = parseInt(toks[0]), m = parseInt(toks[1]);
    s = readline();
    s = ("#" + s + "#").split("");

    for (i = 0; i < m; ++i) {
      toks = readline().split(" ");
      x.push(parseInt(toks[0]));
      c.push(toks[1]);
    }
  }

  function solve() {
    var res = [];
    var num_p, num_s;
    var dots;
    var i;

    dots = false;
    num_p = num_s = 0;
    for (i = 1; i <= n; ++i) {
      if (s[i] == '.') {
        ++num_p;
        if (!dots)
          dots = true, ++num_s;
      }
      else if (dots)
        dots = false;
    }

    for (i = 0; i < m; ++i) {
      if (c[i] == "." && s[x[i]] != ".") {
        ++num_p;
        if (s[x[i] - 1] == "." && s[x[i] + 1] == ".") --num_s;
        if (s[x[i] - 1] != "." && s[x[i] + 1] != ".") ++num_s;
      }
      else if (c[i] != "." && s[x[i]] == ".") {
        --num_p;
        if (s[x[i] - 1] == "." && s[x[i] + 1] == ".") ++num_s;
        if (s[x[i] - 1] != "." && s[x[i] + 1] != ".") --num_s;
      }

      s[x[i]] = c[i];
      res.push(num_p - num_s);
    }

    for (i = 0; i < m; ++i)
      print(res[i]);
  }
}

main();

var input = readline().split(' ').map(Number), n = input[0], m = input[1];
var str = readline().split('');
var groups = 0;
var current = 0;
var f = 0;
for (var i = 0; i < n; i++) {
    if (str[i] == '.') {f++; current++;}
    if ((str[i] != '.' && current > 0) || (str[i] =='.' && i == n-1)) {
        groups++;
        current = 0;
    }
}
str.splice(0,0,'a');
str.splice(str.length, 0, 'a');
while (m--) {
    input = readline().split(' '), idx = parseInt(input[0]), c = input[1];
    var changed = ((c == '.' && str[idx] != '.') || (c != '.' && str[idx] == '.'));
    if (changed) {
        if (str[idx] != '.') f++;
        if (str[idx] == '.') f--;
        if (str[idx - 1] == '.' && str[idx + 1] == '.' && str[idx] == '.')  groups++;
        if (str[idx - 1] == '.' && str[idx + 1] == '.' && str[idx] != '.')  groups--;
        if (str[idx - 1] != '.' && str[idx + 1] != '.' && str[idx] == '.')  groups--;
        if (str[idx - 1] != '.' && str[idx + 1] != '.' && str[idx] != '.')  groups++;
    }
    str[idx] = c;
    write(f-groups, '\n');
}

var input = readline().split(' ').map(Number), n = input[0], m = input[1];
var str = readline().split('');
var groups = 0;
var current = 0;
var f = 0;
for (var i = 0; i < n; i++) {
    if (str[i] == '.') {f++; current++;}
    if ((str[i] != '.' && i < n-1 && current > 0) || (str[i] =='.' && i == n-1)) {
        groups++;
        current = 0;
    }
}
str.splice(0,0,'a');
str.splice(str.length, 0, 'a');
while (m--) {
    input = readline().split(' '), idx = parseInt(input[0]), c = input[1];
    var changed = ((c == '.' && str[idx] != '.') || (c != '.' && str[idx] == '.'));
    if (changed) {
        if (str[idx] != '.') f++;
        if (str[idx] == '.') f--;
        if (str[idx - 1] == '.' && str[idx + 1] == '.' && str[idx] == '.')  groups++;
        if (str[idx - 1] == '.' && str[idx + 1] == '.' && str[idx] != '.')  groups--;
        if (str[idx - 1] != '.' && str[idx + 1] != '.' && str[idx] == '.')  groups--;
        if (str[idx - 1] != '.' && str[idx + 1] != '.' && str[idx] != '.')  groups++;
    }
    str[idx] = c;
    write(f-groups, '\n');
}

var input = readline().split(' ').map(Number), n = input[0], m = input[1];
var str = readline().split('');
var groups = 0;
var current = 0;
var f = 0;
for (var i = 0; i < n; i++) {
    if (str[i] == '.') {f++; current++;}
    if ((str[i] != '.' && current > 0) || (str[i] =='.' && i == n-1)) {
        groups++;
        current = 0;
    }
}
str.splice(0,0,'a');
str.splice(str.length, 0, 'a');
while (m--) {
    write(f, groups, f-groups, '\n');
    input = readline().split(' '), idx = parseInt(input[0]), c = input[1];
    var changed = ((c == '.' && str[idx] != '.') || (c != '.' && str[idx] == '.'));
    if (changed) {
        if (str[idx] != '.') f++;
        if (str[idx] == '.') f--;
        if (str[idx - 1] == '.' && str[idx + 1] == '.' && str[idx] == '.')  groups++;
        if (str[idx - 1] == '.' && str[idx + 1] == '.' && str[idx] != '.')  groups--;
        if (str[idx - 1] != '.' && str[idx + 1] != '.' && str[idx] == '.')  groups--;
        if (str[idx - 1] != '.' && str[idx + 1] != '.' && str[idx] != '.')  groups++;
    }
    str[idx] = c;
    write(f, groups, f-groups, '\n');
    write(f-groups, '\n');
}


Petya and Vasya are tossing a coin. Their friend Valera is appointed as a judge. The game is very simple. First Vasya tosses a coin x times, then Petya tosses a coin y times. If the tossing player gets head, he scores one point. If he gets tail, nobody gets any points. The winner is the player with most points by the end of the game. If boys have the same number of points, the game finishes with a draw.At some point, Valera lost his count, and so he can not say exactly what the score is at the end of the game. But there are things he remembers for sure. He remembers that the entire game Vasya got heads at least a times, and Petya got heads at least b times. Moreover, he knows that the winner of the game was Vasya. Valera wants to use this information to know every possible outcome of the game, which do not contradict his memories.

The single line contains four integers x, y, a, b (1 ≤ a ≤ x ≤ 100, 1 ≤ b ≤ y ≤ 100). The numbers on the line are separated by a space.

In the first line print integer n — the number of possible outcomes of the game. Then on n lines print the outcomes. On the i-th line print a space-separated pair of integers ci, di — the number of heads Vasya and Petya got in the i-th outcome of the game, correspondingly. Print pairs of integers (ci, di) in the strictly increasing order. Let us remind you that the pair of numbers (p1, q1) is less than the pair of numbers (p2, q2), if p1 < p2, or p1 = p2 and also q1 < q2.

print(function(x, y, a, b) {
	var ans = [];

	for (var i = Math.max(a,b+1); i <= x; i++)
		for (var j = b, l = Math.min(i-1,y); j <= l; j++)
			ans.push(i + ' ' + j);

	ans.unshift(ans.length);

	return ans.join('\n');

} .apply(0, readline().split(' ').map(Number)));

print(function(x, y, a, b) {
	var ans = [];

	for (var i = Math.max(a,b+1); i <= x; i++)
		for (var j = b, l = Math.min(i-1,y); j <= l; j++)
			ans.push(i + ' ' + j);

	return ans.length + (ans.length > 0 ? '\n' + ans.join('\n') : '');

} .apply(0, readline().split(' ').map(Number)));

;(function () {

	print(function (x, y, a, b) {
		var n = 0, r = [];

		while (b <= y) {
			var _a = Math.max(a, b), _b = b;
			while (_a <= x) {
				if (_a > _b) {
					r.push([_a, _b]);
					n++;
				}
				_a++;
			}
			b++;
		}

		return n + '\n' + r.sort(function (a, b) { return (a[0] - b[0])*1000 + a[1] - b[1]; }).map(function (e) { return e.join(' '); }).join('\n');
	}.apply(0, readline().split(' ').map(Number)));

}).call(this);

function trim(s) {
	return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
	return trim(s).split(/\s+/);
}

function tokenizeIntegers(s) {
	var tokens = tokenize(s);
	for (var i = 0; i < tokens.length; i += 1) {
		tokens[i] = parseInt(tokens[i], 10);
	};
	return tokens;
}

function main() {
	var data = tokenizeIntegers(readline()),
		x = data[0], y = data[1], a = data[2], b = data[3],
		lines = [];
	for (var i = Math.max(a, b+1); i <= x; ++i) {
		for (var j = b; j < i; ++j) {
			if (j > y) {
				break;
			}
			lines.push(i+' '+j);
		}
	}
	print(lines.length);
	if (lines.length != 0) {
		print(lines.join('\n'));
	}
}

main();

print(function(x, y, a, b) {
	var ans = [];

	for (var i = Math.max(a,b+1); i <= x; i++)
		for (var j = Math.min(i-1,y); j >= b; j--)
			ans.push(i + ' ' + j);

	return ans.length + (ans.length > 0 ? '\n' + ans.join('\n') : '');

} .apply(0, readline().split(' ').map(Number)));

;(function () {

	print(function (x, y, a, b) {
		var n = 0, r = [];

		while (b <= y) {
			var _a = Math.max(a, b), _b = b;
			while (_a <= x) {
				if (_a > _b) {
					r.push([_a, _b]);
					n++;
				}
				_a++;
			}
			b++;
		}

		return n + '\n' + r.map(function (e) { return e.join(' '); }).join('\n');
	}.apply(0, readline().split(' ').map(Number)));

}).call(this);

;(function () {

	print(function (x, y, a, b) {
		var n = 0, r = [];

		while (b <= y) {
			var _a = Math.max(a, b), _b = b;
			while (_a <= x) {
				if (_a > _b) r.push([_a, _b]);
				_a++;
			}
			b++;
		}

		return n + '\n' + r.map(function (e) { return e.join(' '); }).join('\n');
	}.apply(0, readline().split(' ').map(Number)));

}).call(this);

function trim(s) {
	return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
	return trim(s).split(/\s+/);
}

function tokenizeIntegers(s) {
	var tokens = tokenize(s);
	for (var i = 0; i < tokens.length; i += 1) {
		tokens[i] = parseInt(tokens[i], 10);
	};
	return tokens;
}

function main() {
	var data = tokenizeIntegers(readline()),
		x = data[0], y = data[1], a = data[2], b = data[3],
		lines = [];
	for (var i = Math.max(a, b+1); i <= x; ++i) {
		for (var j = b; j < i; ++j) {
			lines.push(i+' '+j);
		}
	}
	print(lines.length);
	if (lines.length != 0) {
		print(lines.join('\n'));
	}
}

main();


An infinitely long railway has a train consisting of n cars, numbered from 1 to n (the numbers of all the cars are distinct) and positioned in arbitrary order. David Blaine wants to sort the railway cars in the order of increasing numbers. In one move he can make one of the cars disappear from its place and teleport it either to the beginning of the train, or to the end of the train, at his desire. What is the minimum number of actions David Blaine needs to perform in order to sort the train?

The first line of the input contains integer n (1 ≤ n ≤ 100 000) — the number of cars in the train.  The second line contains n integers pi (1 ≤ pi ≤ n, pi ≠ pj if i ≠ j) — the sequence of the numbers of the cars in the train.

Print a single integer — the minimum number of actions needed to sort the railway cars.

NoteIn the first sample you need first to teleport the 4-th car, and then the 5-th car to the end of the train.

function getMinSteps (a,b) {
  var countMinSteps = 0;

  var pos = Array.apply(null, Array(a+2)).map(Number.prototype.valueOf,0);

  for (var i=0; i<a; i++) {
    var item = b[i];

    pos[item] = pos[item-1] + 1;
  }

  countMinSteps = a - Math.max.apply(Math, pos);
  return countMinSteps;
}

var a = parseInt(readline());
var b = readline().split(" ").map(function(secondLine) { return parseInt(secondLine); });

print(getMinSteps (a,b));