#include <iostream>
#include <vector>

int main()
{
	int n, q;
	std::cin >> n >> q;

	std::string str;
	std::cin >> str;

	for (int i = 0; i < q; i++)
	{
		int b, e;
		std::cin >> b >> e;

		int asd = e - b + 1;

		if (str[0] == '?')
		{
			std::cout << (asd / 2) * (asd - (asd / 2));
		}
		else
		{
			int brsedam = 0;
			int trulost = 0;
			for (int j = b - 1; j <= e; j--)
			{
				if (str[j] == '7')
					brsedam++;
				else if (str[j] == '6')
					trulost += brsedam;
			}

			std::cout << trulost;
		}
	}

	// std::cout << "nigga balls";
}