#include <iostream>
#include <vector>

int drugaTrulost(std::string s)
{
	int br = 0;
	int e = 0;
	char c;
	for (int i = 0; i < s.size(); i++)
	{
		c = s[i];
		e = i;
		if (c == '7')
			break;

		br++;
	}

	return br * (s.size() - e);
}

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;

		b -= 1;

		int bu = 0;
		for (int j = b; j < e; j++)
		{
			if (str[j] == '?')
				bu++;
		}

		int brsest = bu / 2;

		std::string s = "";
		std::string s2 = "";

		for (int j = b; j < e; j++)
		{
			if (str[j] == '?')
			{
				if (brsest > 0)
				{
					s += '6';
					brsest--;
				}
				else
					s += '7';
			}
			else
				s += str[j];

			s2 += str[j];
		}

		int brsedam = 0;
		int trulost = 0;

		for (int j = s.size() - 1; j >= 0; j--)
		{
			if (s[j] == '7')
				brsedam++;
			else if (s[j] == '6')
				trulost += brsedam;
		}

		std::cout << std::max(trulost, drugaTrulost(s2)) << "\n";
	}
}