https://www.codechef.com/CENS2020/problems/CENS20G/

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

int main() {

ios_base::sync_with_stdio(false);cin.tie(NULL);

#ifndef ONLINE_JUDGE
freopen(“input.txt”, “r”, stdin);
freopen(“output.txt”, “w”, stdout);
#endif

int t; cin >> t;
while (t--) {
	string s;
	cin >> s;
	int x1, y1; cin >> x1 >> y1;
	int freq[26] = {0};
	for (int i = 0; i < s.size(); i++) {
		int x = s[i];
		freq[x - 'A']++;
	}

	int q; cin >> q;
	while (q--) {


		bool f = 0;
		int x2, y2; cin >> x2 >> y2;
		int a = x2 - x1;
		int b = y2 - y1;
		// cout << a << " " << b << endl;
		int ans = abs(a) + abs(b);

		if (a > 0 && freq['R' - 'A'] < a) {
			f = 1;
		}

		else if (a < 0 && freq['L' - 'A'] < (-1 * a)) {
			f = 1;
		}

		else if (b > 0 && freq['U' - 'A'] < b)
			f = 1;

		else if (b < 0 && freq['D' - 'A'] < (-1 * b))
			f = 1;

		// cout << f << endl;

		if (f == 1)cout << "NO" << endl;
		else
			cout << "YES" << " " << ans << endl;



	}
}
return 0;

}

On submission this is giving TLE plz tell me why?