import java.io.*;
import java.util.*;

public class MainD {
	static final StdIn in = new StdIn();
	static final PrintWriter out = new PrintWriter(System.out);
	static final long M=(long)1e9+7;
	static int n=in.nextInt(), m=in.nextInt();
	static Map<Integer, Node> graph = new HashMap<Integer, Node>();

	public static void main(String[] args) {
		addNode(1);
		for(int i=0; i<m; ++i) {
			int u=in.nextInt(), v=in.nextInt();
			addNode(u).adj.add(v);
			addNode(v).adj.add(u);
		}
		for(Map.Entry<Integer, Node> nodeEntry : graph.entrySet()) {
			Node u=nodeEntry.getValue();
			for(int i=u.adj.size()-1; i>=0; --i) {
				if(!graph.containsKey(u.adj.get(i))) {
					u.s+=sts(u.adj.get(i));
					u.adj.remove(i);
				}
			}
		}
		long ans=0;
		for(Map.Entry<Integer, Node> nodeEntry : graph.entrySet())
			ans=(dfs(nodeEntry.getKey(), 0)+ans)%M;
		out.println(ans);
		out.close();
	}

	static Node addNode(int u) {
		if(u<=0)
			return null;
		Node node = graph.get(u);
		if(node!=null)
			return node;
		node = new Node();
		if(u>1)
			node.adj.add(u/2);
		if(u*2<=n)
			node.adj.add(u*2);
		if(u*2+1<=n)
			node.adj.add(u*2+1);
		graph.put(u, node);
		addNode(u/2);
		return node;
	}

	static long sts(int u) {
		long res=0;
		int l=u, r=u;
		while(r<=n) {
			res+=r-l+1;
			l=2*l;
			r=2*r+1;
		}
		return (res+Math.min(r, n)-Math.min(l, n))%M;
	}

	static long dfs(int u, long ps) {
		Node node=graph.get(u);
		if(ps==0)
			ps=node.s;
		node.active=true;
		long res=ps*node.s;
		for(int v : node.adj)
			if(!graph.get(v).active)
				res+=dfs(v, ps);
		node.active=false;
		return res;
	}

	static class Node {
		List<Integer> adj = new ArrayList<Integer>();
		long s=1;
		boolean active;
	}

	interface Input {
		public String next();
		public String nextLine();
		public int nextInt();
		public long nextLong();
		public double nextDouble();
	}
	static class StdIn implements Input {
		final private int BUFFER_SIZE = 1 << 16;
		private DataInputStream din;
		private byte[] buffer;
		private int bufferPointer, bytesRead;
		public StdIn() {
			din = new DataInputStream(System.in);
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}
		public StdIn(InputStream in) {
			try{
				din = new DataInputStream(in);
			} catch(Exception e) {
				throw new RuntimeException();
			}
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}
		public String next() {
			int c;
			while((c=read())!=-1&&(c==' '||c=='\n'||c=='\r'));
			StringBuilder s = new StringBuilder();
			while (c != -1)
			{
				if (c == ' ' || c == '\n'||c=='\r')
					break;
				s.append((char)c);
				c=read();
			}
			return s.toString();
		}
		public String nextLine() {
			int c;
			while((c=read())!=-1&&(c==' '||c=='\n'||c=='\r'));
			StringBuilder s = new StringBuilder();
			while (c != -1)
			{
				if (c == '\n'||c=='\r')
					break;
				s.append((char)c);
				c = read();
			}
			return s.toString();
		}
		public int nextInt() {
			int ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do
				ret = ret * 10 + c - '0';
			while ((c = read()) >= '0' && c <= '9');

			if (neg)
				return -ret;
			return ret;
		}
		public int[] readIntArray(int n) {
			int[] ar = new int[n];
			for(int i=0; i<n; ++i)
				ar[i]=nextInt();
			return ar;
		}
		public long nextLong() {
			long ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do
				ret = ret * 10 + c - '0';
			while ((c = read()) >= '0' && c <= '9');
			if (neg)
				return -ret;
			return ret;
		}
		public long[] readLongArray(int n) {
			long[] ar = new long[n];
			for(int i=0; i<n; ++i)
				ar[i]=nextLong();
			return ar;
		}
		public double nextDouble() {
			double ret = 0, div = 1;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do
				ret = ret * 10 + c - '0';
			while ((c = read()) >= '0' && c <= '9');
			if (c == '.')
				while ((c = read()) >= '0' && c <= '9')
					ret += (c - '0') / (div *= 10);
			if (neg)
				return -ret;
			return ret;
		}
		private void fillBuffer() throws IOException {
			bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
			if (bytesRead == -1)
				buffer[0] = -1;
		}
		private byte read() {
			try{
				if (bufferPointer == bytesRead)
					fillBuffer();
				return buffer[bufferPointer++];
			} catch(IOException e) {
				throw new RuntimeException();
			}
		}
		public void close() throws IOException {
			if (din == null)
				return;
			din.close();
		}
	}
}


//package eightvc.f;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class F {
	InputStream is;
	PrintWriter out;
	String INPUT = "";
	char[] s;
	int pos, len;
	int mod = 1000000007;
	int emod = mod-1;
	long modx = (long)mod*emod;

	long[] tm = new long[64];

	long tes(long nume, long mul)
	{
		long B = mul;
		long s0 = 1;
		long s1 = 0;
		long res1 = 0;
		for(int d = 0;d < 63;d++){
			if(nume<<~d<0){
				res1 = (res1 * B + s1 + s0*((nume&(1L<<d)-1)%mod)) % mod;
			}
//			s1 = (s1 * (B+1) + (s0<<d)) % mod;
			s1 = (s1 * (B+1) + s0*((1L<<d)%mod)) % mod;
			s0 = s0 * (B+1) % mod;
			B = B * B % mod;
		}
		return res1;
	}

	void solve()
	{
		for(int i = 0;i < 63;i++){
			tm[i] = (1L<<i)%mod;
		}

		s = ns().toCharArray();
		pos = 0; len = s.length;
		Modnum res = expr();
		assert pos == len;
		out.println(res.v);
	}

	Modnum expr()
	{
		Modnum t = term();
		while(pos < len && s[pos] == '+'){
			pos++;
			Modnum lt = term();
			t = concat(t, lt);
		}
		return t;
	}

	Modnum term()
	{
		Modnum n = number();
		if(pos < len && s[pos] == '-'){
			pos++;
			Modnum ln = number();
			return range(n, ln);
		}
		if(pos < len && s[pos] == '('){
			pos++;
			Modnum e = expr();
			assert s[pos] == ')';
			pos++;
			return repeat(e, n);
		}
		return n;
	}

	Modnum number()
	{
		long vx = 0;
		int nlen = 0;
		while(pos < len && s[pos] >= '0' && s[pos] <= '9'){
			long vx2 = vx + vx;
			if(vx2 >= modx)vx2 -= modx;
			vx = vx2 * 5 + (s[pos]-'0');
			while(vx >= modx)vx -= modx;
			nlen++;
			pos++;
		}
		assert nlen != 0;
		return new Modnum(vx%mod, nlen, vx);
	}

	Modnum concat(Modnum a, Modnum b)
	{
		a.v = (a.v * pow(10, b.len, mod) + b.v)% mod;
		a.len += b.len;
		if(a.len >= emod)a.len -= emod;
		return a;
//		return new Modnum(
//				(a.v * pow(10, b.len, mod) + b.v)% mod,
//				(a.len + b.len) % emod
//		);
	}

	Modnum range(Modnum a, Modnum b)
	{
		Modnum ret = new Modnum(0, 0);
		long t = pow(10, a.len, mod);
		for(long i = a.len;i <= b.len;i++){
			long inf = i == a.len ? a.v : pow(10, i-1, mod);
//			long sup = i == b.len ? b.v : pow(10, i, mod)-1;
			long infe = i == a.len ? a.vx : powSafe(10, i-1, modx);
			long supe = i == b.len ? b.vx : powSafe(10, i, modx)-1;
//			if(sup < 0)sup += mod;
			if(supe < 0)supe += modx;

			long nume = supe-infe+1;
			if(nume < 0)nume += modx;
			long base = inf*sumGP(t, nume, mod)%mod;
			// 0 1 ... sup-inf

			nume %= modx;
			long mul = t;
			long B = mul;
			long s0 = 1;
			long s1 = 0;
			long res1 = 0;
			long q = 0;
			for(int d = 0;d < 63;d++){
				if(nume<<~d<0){
//					res1 = (res1 * B + s1 + s0*((nume&(1L<<d)-1)%mod)) % mod;
					res1 = (res1 * B + s1 + s0*q) % mod;
					q += tm[d];
					if(q >= mod)q -= mod;
				}
//				s1 = (s1 * (B+1) + (s0<<d)) % mod;
//				s1 = (s1 * (B+1) + s0*((1L<<d)%mod)) % mod;
				s1 = (s1 * (B+1) + s0*tm[d]) % mod;
				s0 = s0 * (B+1) % mod;
				B = B * B % mod;
			}
			t = t * 10 % mod;

			ret = concat(ret, new Modnum((base+res1)%mod, i*(nume%emod)%emod));
		}
		return ret;
	}

	Modnum repeat(Modnum a, Modnum rep)
	{
		return new Modnum(
				sumGP(pow(10, a.len, mod), rep.vx, mod) * a.v % mod,
				a.len*(rep.vx%emod)%emod
				);
	}

	public static class Modnum
	{
		public long v;
		public long vx;
		public long len;
		public Modnum(long v, long len) {
			this.v = v;
			this.len = len;
		}
		public Modnum(long v, long len, long vx) {
			this.v = v;
			this.len = len;
			this.vx = vx;
		}
		@Override
		public String toString() {
			return "Datum [v=" + v + ", len=" + len + "]";
		}
	}

	public static long powSafe(long a, long n, long mod)
	{
//		a %= mod;
		long ret = 1; // 1%mod if mod=1,n=0
		int x = 63-Long.numberOfLeadingZeros(n);
		for(;x >= 0;x--){
			ret = mulEx(ret, ret, mod);
			if(n<<~x<0)ret = mulEx(ret, a, mod);
		}
		return ret;
	}

	public static long mul(long a, long b, long mod)
	{
		if(a >= mod || a < 0)a %= mod;
		if(a < 0)a += mod;
		if(b >= mod || b < 0)b %= mod;
		if(b < 0)b += mod;

		long ret = 0;
		int x = 63-Long.numberOfLeadingZeros(b);
		for(;x >= 0;x--){
			ret += ret;
			if(ret >= mod)ret -= mod;
			if(b<<~x<0){
				ret += a;
				if(ret >= mod)ret -= mod;
			}
		}
		return ret;
	}

	public static long mulEx(long a, long b, long mod)
	{
		if(a >= mod || a < 0)a %= mod;
		if(a < 0)a += mod;
		if(b >= mod || b < 0)b %= mod;
		if(b < 0)b += mod;

		long ret = 0;
		int x = 63-Long.numberOfLeadingZeros(b);
		for(;x >= 0;x--){
			ret += ret;
			if(Long.compareUnsigned(ret, mod) >= 0)ret -= mod;
			if(b<<~x<0){
				ret += a;
				if(Long.compareUnsigned(ret, mod) >= 0)ret -= mod;
			}
		}
		return ret;
	}

	public static long sumGP(long a, long n, long mod)
	{
		long smul = 1; // % mod
		long mul = a % mod;
		long ret = 0;
		for(;n > 0;n >>>= 1){
			if((n&1)==1){
				ret = (ret * mul + smul) % mod;
			}
			smul = smul * (mul + 1) % mod;
			mul = mul * mul % mod;
		}
		return ret;
	}

	public static long pow(long a, long n, long mod) {
		//		a %= mod;
		long ret = 1;
		int x = 63 - Long.numberOfLeadingZeros(n);
		for (; x >= 0; x--) {
			ret = ret * ret % mod;
			if (n << 63 - x < 0)
				ret = ret * a % mod;
		}
		return ret;
	}

	void run() throws Exception
	{
		is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		tr(System.currentTimeMillis()-s+"ms");
	}

	public static void main(String[] args) throws Exception { new F().run(); }

	private byte[] inbuf = new byte[1024];
	public int lenbuf = 0, ptrbuf = 0;

	private int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf){
			ptrbuf = 0;
			try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
	private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

	private double nd() { return Double.parseDouble(ns()); }
	private char nc() { return (char)skip(); }

	private String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n)
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while(p < n && !(isSpaceChar(b))){
			buf[p++] = (char)b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private char[][] nm(int n, int m)
	{
		char[][] map = new char[n][];
		for(int i = 0;i < n;i++)map[i] = ns(m);
		return map;
	}

	private int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}

	private int ni()
	{
		int num = 0, b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private long nl()
	{
		long num = 0;
		int b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
	private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}


//package eightvc.f;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class F {
	InputStream is;
	PrintWriter out;
	String INPUT = "";
	char[] s;
	int pos, len;
	int mod = 1000000007;
	int emod = mod-1;
	long modx = (long)mod*emod;

	long tes(long nume, long mul)
	{
		long B = mul;
		long s0 = 1;
		long s1 = 0;
		long res1 = 0;
		for(int d = 0;d < 63;d++){
			if(nume<<~d<0){
				res1 = (res1 * B + s1 + s0*((nume&(1L<<d)-1)%mod)) % mod;
			}
//			s1 = (s1 * (B+1) + (s0<<d)) % mod;
			s1 = (s1 * (B+1) + s0*((1L<<d)%mod)) % mod;
			s0 = s0 * (B+1) % mod;
			B = B * B % mod;
		}
		return res1;
	}

	void solve()
	{
		s = ns().toCharArray();
		pos = 0; len = s.length;
		Modnum res = expr();
		assert pos == len;
		out.println(res.v);
	}

	Modnum expr()
	{
		Modnum t = term();
		while(pos < len && s[pos] == '+'){
			pos++;
			Modnum lt = term();
			t = concat(t, lt);
		}
		return t;
	}

	Modnum term()
	{
		Modnum n = number();
		if(pos < len && s[pos] == '-'){
			pos++;
			Modnum ln = number();
			return range(n, ln);
		}
		if(pos < len && s[pos] == '('){
			pos++;
			Modnum e = expr();
			assert s[pos] == ')';
			pos++;
			return repeat(e, n);
		}
		return n;
	}

	Modnum number()
	{
		long vx = 0;
		int nlen = 0;
		while(pos < len && s[pos] >= '0' && s[pos] <= '9'){
			long vx2 = vx + vx;
			if(vx2 >= modx)vx2 -= modx;
			vx = vx2 * 5 + (s[pos]-'0');
			while(vx >= modx)vx -= modx;
			nlen++;
			pos++;
		}
		assert nlen != 0;
		return new Modnum(vx%mod, nlen, vx);
	}

//	Modnum number()
//	{
//		long v = 0;
//		long vx = 0;
//		int nlen = 0;
//		while(pos < len && s[pos] >= '0' && s[pos] <= '9'){
//			v = v * 10 + (s[pos]-'0');
//			v %= mod;
//			vx = mulEx(vx, 10, modx) + (s[pos]-'0');
//			if(vx >= modx)vx -= modx;
//			nlen++;
//			pos++;
//		}
//		assert nlen != 0;
//		return new Modnum(v, nlen, vx);
//	}
//
	Modnum concat(Modnum a, Modnum b)
	{
		return new Modnum(
				(a.v * pow(10, b.len, mod) + b.v)% mod,
				(a.len + b.len) % emod
		);
	}

	Modnum range(Modnum a, Modnum b)
	{
		Modnum ret = new Modnum(0, 0);
		long t = pow(10, a.len, mod);
		for(long i = a.len;i <= b.len;i++){
			long inf = i == a.len ? a.v : pow(10, i-1, mod);
//			long sup = i == b.len ? b.v : pow(10, i, mod)-1;
			long infe = i == a.len ? a.vx : powSafe(10, i-1, modx);
			long supe = i == b.len ? b.vx : powSafe(10, i, modx)-1;
//			if(sup < 0)sup += mod;
			if(supe < 0)supe += modx;

			long nume = supe-infe+1;
			if(nume < 0)nume += modx;
			long base = inf*sumGP(t, nume, mod)%mod;
			// 0 1 ... sup-inf

			nume %= modx;
			long mul = t;
			long B = mul;
			long s0 = 1;
			long s1 = 0;
			long res1 = 0;
			for(int d = 0;d < 63;d++){
				if(nume<<~d<0){
					res1 = (res1 * B + s1 + s0*((nume&(1L<<d)-1)%mod)) % mod;
				}
//				s1 = (s1 * (B+1) + (s0<<d)) % mod;
				s1 = (s1 * (B+1) + s0*((1L<<d)%mod)) % mod;
				s0 = s0 * (B+1) % mod;
				B = B * B % mod;
			}
			t = t * 10 % mod;

			ret = concat(ret, new Modnum((base+res1)%mod, i*(nume%emod)%emod));
		}
		return ret;
	}

	Modnum repeat(Modnum a, Modnum rep)
	{
		return new Modnum(
				sumGP(pow(10, a.len, mod), rep.vx, mod) * a.v % mod,
				a.len*(rep.vx%emod)%emod
				);
	}

	public static class Modnum
	{
		public long v;
		public long vx;
		public long len;
		public Modnum(long v, long len) {
			this.v = v;
			this.len = len;
		}
		public Modnum(long v, long len, long vx) {
			this.v = v;
			this.len = len;
			this.vx = vx;
		}
		@Override
		public String toString() {
			return "Datum [v=" + v + ", len=" + len + "]";
		}
	}

	public static long powSafe(long a, long n, long mod)
	{
//		a %= mod;
		long ret = 1; // 1%mod if mod=1,n=0
		int x = 63-Long.numberOfLeadingZeros(n);
		for(;x >= 0;x--){
			ret = mulEx(ret, ret, mod);
			if(n<<~x<0)ret = mulEx(ret, a, mod);
		}
		return ret;
	}

	public static long mul(long a, long b, long mod)
	{
		if(a >= mod || a < 0)a %= mod;
		if(a < 0)a += mod;
		if(b >= mod || b < 0)b %= mod;
		if(b < 0)b += mod;

		long ret = 0;
		int x = 63-Long.numberOfLeadingZeros(b);
		for(;x >= 0;x--){
			ret += ret;
			if(ret >= mod)ret -= mod;
			if(b<<~x<0){
				ret += a;
				if(ret >= mod)ret -= mod;
			}
		}
		return ret;
	}

	public static long mulEx(long a, long b, long mod)
	{
		if(a >= mod || a < 0)a %= mod;
		if(a < 0)a += mod;
		if(b >= mod || b < 0)b %= mod;
		if(b < 0)b += mod;

		long ret = 0;
		int x = 63-Long.numberOfLeadingZeros(b);
		for(;x >= 0;x--){
			ret += ret;
			if(Long.compareUnsigned(ret, mod) >= 0)ret -= mod;
			if(b<<~x<0){
				ret += a;
				if(Long.compareUnsigned(ret, mod) >= 0)ret -= mod;
			}
		}
		return ret;
	}

	public static long sumGP(long a, long n, long mod)
	{
		long smul = 1; // % mod
		long mul = a % mod;
		long ret = 0;
		for(;n > 0;n >>>= 1){
			if((n&1)==1){
				ret = (ret * mul + smul) % mod;
			}
			smul = smul * (mul + 1) % mod;
			mul = mul * mul % mod;
		}
		return ret;
	}

	public static long pow(long a, long n, long mod) {
		//		a %= mod;
		long ret = 1;
		int x = 63 - Long.numberOfLeadingZeros(n);
		for (; x >= 0; x--) {
			ret = ret * ret % mod;
			if (n << 63 - x < 0)
				ret = ret * a % mod;
		}
		return ret;
	}

	void run() throws Exception
	{
		is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		tr(System.currentTimeMillis()-s+"ms");
	}

	public static void main(String[] args) throws Exception { new F().run(); }

	private byte[] inbuf = new byte[1024];
	public int lenbuf = 0, ptrbuf = 0;

	private int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf){
			ptrbuf = 0;
			try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
	private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

	private double nd() { return Double.parseDouble(ns()); }
	private char nc() { return (char)skip(); }

	private String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n)
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while(p < n && !(isSpaceChar(b))){
			buf[p++] = (char)b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private char[][] nm(int n, int m)
	{
		char[][] map = new char[n][];
		for(int i = 0;i < n;i++)map[i] = ns(m);
		return map;
	}

	private int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}

	private int ni()
	{
		int num = 0, b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private long nl()
	{
		long num = 0;
		int b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
	private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}


//package eightvc.f;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class F {
	InputStream is;
	PrintWriter out;
	String INPUT = "";
	char[] s;
	int pos, len;
	int mod = 1000000007;
	int emod = mod-1;
	long modx = (long)mod*emod;

	long tes(long nume, long mul)
	{
		long B = mul;
		long s0 = 1;
		long s1 = 0;
		long res1 = 0;
		for(int d = 0;d < 63;d++){
			if(nume<<~d<0){
				res1 = (res1 * B + s1 + s0*((nume&(1L<<d)-1)%mod)) % mod;
			}
//			s1 = (s1 * (B+1) + (s0<<d)) % mod;
			s1 = (s1 * (B+1) + s0*pow(2,d,mod)) % mod;
			s0 = s0 * (B+1) % mod;
			B = B * B % mod;
		}
		return res1;
	}

	void solve()
	{
//		for(int i = 0;i < 10;i++){
//			tr(tes(i, 10));
//		}
////		tr("AI");
////		tr(tes(mod+1, 10));
////		tr(tes((long)mod*(mod-1), 10));
////		tr(tes((long)emod*emod, 10));
//
//		if(true)return;
		s = ns().toCharArray();
		pos = 0; len = s.length;
		Modnum res = expr();
		assert pos == len;
		out.println(res.v);
	}

	Modnum expr()
	{
		Modnum t = term();
		while(pos < len && s[pos] == '+'){
			pos++;
			Modnum lt = term();
			t = concat(t, lt);
		}
		return t;
	}

	Modnum term()
	{
		Modnum n = number();
		if(pos < len && s[pos] == '-'){
			pos++;
			Modnum ln = number();
			return range(n, ln);
		}
		if(pos < len && s[pos] == '('){
			pos++;
			Modnum e = expr();
			assert s[pos] == ')';
			pos++;
			return repeat(e, n);
		}
		return n;
	}

	Modnum number()
	{
		long v = 0;
		long vx = 0;
		int nlen = 0;
		while(pos < len && s[pos] >= '0' && s[pos] <= '9'){
			v = v * 10 + (s[pos]-'0');
			v %= mod;
			vx = mulEx(vx, 10, modx) + (s[pos]-'0');
			if(vx >= modx)vx -= modx;
			nlen++;
			pos++;
		}
		assert nlen != 0;
		return new Modnum(v, nlen, vx);
	}

	Modnum concat(Modnum a, Modnum b)
	{
		return new Modnum(
				(a.v * pow(10, b.len, mod) + b.v)% mod,
				(a.len + b.len) % emod
		);
	}

	Modnum range(Modnum a, Modnum b)
	{
		Modnum ret = new Modnum(0, 0);
		for(long i = a.len;i <= b.len;i++){
			long inf = i == a.len ? a.v : pow(10, i-1, mod);
			long sup = i == b.len ? b.v : pow(10, i, mod)-1;
			long infe = i == a.len ? a.vx : powSafe(10, i-1, modx);
			long supe = i == b.len ? b.vx : powSafe(10, i, modx)-1;
			if(sup < 0)sup += mod;
			if(supe < 0)supe += modx;

			long nume = supe-infe+1;
			if(nume < 0)nume += modx;
			long base = inf*sumGP(pow(10, i, mod), nume, mod)%mod;
			// 0 1 ... sup-inf

			nume %= modx;
			long mul = pow(10, i, mod);
			long B = mul;
			long s0 = 1;
			long s1 = 0;
			long res1 = 0;
			for(int d = 0;d < 63;d++){
				if(nume<<~d<0){
					res1 = (res1 * B + s1 + s0*((nume&(1L<<d)-1)%mod)) % mod;
				}
//				s1 = (s1 * (B+1) + (s0<<d)) % mod;
				s1 = (s1 * (B+1) + s0*pow(2,d,mod)) % mod;
				s0 = s0 * (B+1) % mod;
				B = B * B % mod;
			}

			ret = concat(ret, new Modnum((base+res1)%mod, i*(nume%emod)%emod));
		}
		return ret;
	}

	Modnum repeat(Modnum a, Modnum rep)
	{
		return new Modnum(
				sumGP(pow(10, a.len, mod), rep.vx, mod) * a.v % mod,
				a.len*(rep.vx%emod)%emod
				);
	}

	public static class Modnum
	{
		public long v;
		public long vx;
		public long len;
		public Modnum(long v, long len) {
			this.v = v;
			this.len = len;
		}
		public Modnum(long v, long len, long vx) {
			this.v = v;
			this.len = len;
			this.vx = vx;
		}
		@Override
		public String toString() {
			return "Datum [v=" + v + ", len=" + len + "]";
		}
	}

	public static long powSafe(long a, long n, long mod)
	{
//		a %= mod;
		long ret = 1; // 1%mod if mod=1,n=0
		int x = 63-Long.numberOfLeadingZeros(n);
		for(;x >= 0;x--){
			ret = mulEx(ret, ret, mod);
			if(n<<~x<0)ret = mulEx(ret, a, mod);
		}
		return ret;
	}

	public static long mul(long a, long b, long mod)
	{
		if(a >= mod || a < 0)a %= mod;
		if(a < 0)a += mod;
		if(b >= mod || b < 0)b %= mod;
		if(b < 0)b += mod;

		long ret = 0;
		int x = 63-Long.numberOfLeadingZeros(b);
		for(;x >= 0;x--){
			ret += ret;
			if(ret >= mod)ret -= mod;
			if(b<<~x<0){
				ret += a;
				if(ret >= mod)ret -= mod;
			}
		}
		return ret;
	}

	public static long mulEx(long a, long b, long mod)
	{
		if(a >= mod || a < 0)a %= mod;
		if(a < 0)a += mod;
		if(b >= mod || b < 0)b %= mod;
		if(b < 0)b += mod;

		long ret = 0;
		int x = 63-Long.numberOfLeadingZeros(b);
		for(;x >= 0;x--){
			ret += ret;
			if(Long.compareUnsigned(ret, mod) >= 0)ret -= mod;
			if(b<<~x<0){
				ret += a;
				if(Long.compareUnsigned(ret, mod) >= 0)ret -= mod;
			}
		}
		return ret;
	}

	public static long sumGP(long a, long n, long mod)
	{
		long smul = 1; // % mod
		long mul = a % mod;
		long ret = 0;
		for(;n > 0;n >>>= 1){
			if((n&1)==1){
				ret = (ret * mul + smul) % mod;
			}
			smul = smul * (mul + 1) % mod;
			mul = mul * mul % mod;
		}
		return ret;
	}

	public static long pow(long a, long n, long mod) {
		//		a %= mod;
		long ret = 1;
		int x = 63 - Long.numberOfLeadingZeros(n);
		for (; x >= 0; x--) {
			ret = ret * ret % mod;
			if (n << 63 - x < 0)
				ret = ret * a % mod;
		}
		return ret;
	}

	void run() throws Exception
	{
		is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		tr(System.currentTimeMillis()-s+"ms");
	}

	public static void main(String[] args) throws Exception { new F().run(); }

	private byte[] inbuf = new byte[1024];
	public int lenbuf = 0, ptrbuf = 0;

	private int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf){
			ptrbuf = 0;
			try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
	private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

	private double nd() { return Double.parseDouble(ns()); }
	private char nc() { return (char)skip(); }

	private String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n)
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while(p < n && !(isSpaceChar(b))){
			buf[p++] = (char)b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private char[][] nm(int n, int m)
	{
		char[][] map = new char[n][];
		for(int i = 0;i < n;i++)map[i] = ns(m);
		return map;
	}

	private int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}

	private int ni()
	{
		int num = 0, b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private long nl()
	{
		long num = 0;
		int b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
	private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}


//package eightvc.f;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class F {
	InputStream is;
	PrintWriter out;
	String INPUT = "";
	char[] s;
	int pos, len;
	int mod = 1000000007;
	int emod = mod-1;
	long modx = (long)mod*emod;

	long tes(long nume, long mul)
	{
		long B = mul;
		long s0 = 1;
		long s1 = 0;
		long res1 = 0;
		for(int d = 0;d < 63;d++){
			if(nume<<~d<0){
				res1 = (res1 * B + s1 + s0*((nume&(1L<<d)-1)%mod)) % mod;
			}
//			s1 = (s1 * (B+1) + (s0<<d)) % mod;
			s1 = (s1 * (B+1) + s0*((1L<<d)%mod)) % mod;
			s0 = s0 * (B+1) % mod;
			B = B * B % mod;
		}
		return res1;
	}

	void solve()
	{
		s = ns().toCharArray();
		pos = 0; len = s.length;
		Modnum res = expr();
		assert pos == len;
		out.println(res.v);
	}

	Modnum expr()
	{
		Modnum t = term();
		while(pos < len && s[pos] == '+'){
			pos++;
			Modnum lt = term();
			t = concat(t, lt);
		}
		return t;
	}

	Modnum term()
	{
		Modnum n = number();
		if(pos < len && s[pos] == '-'){
			pos++;
			Modnum ln = number();
			return range(n, ln);
		}
		if(pos < len && s[pos] == '('){
			pos++;
			Modnum e = expr();
			assert s[pos] == ')';
			pos++;
			return repeat(e, n);
		}
		return n;
	}

	Modnum number()
	{
		long vx = 0;
		int nlen = 0;
		while(pos < len && s[pos] >= '0' && s[pos] <= '9'){
			long vx2 = vx + vx;
			if(vx2 >= modx)vx2 -= modx;
			vx = vx2 * 5 + (s[pos]-'0');
			while(vx >= modx)vx -= modx;
			nlen++;
			pos++;
		}
		assert nlen != 0;
		return new Modnum(vx%mod, nlen, vx);
	}

	Modnum concat(Modnum a, Modnum b)
	{
		a.v = (a.v * pow(10, b.len, mod) + b.v)% mod;
		a.len += b.len;
		if(a.len >= emod)a.len -= emod;
		return a;
//		return new Modnum(
//				(a.v * pow(10, b.len, mod) + b.v)% mod,
//				(a.len + b.len) % emod
//		);
	}

	Modnum range(Modnum a, Modnum b)
	{
		Modnum ret = new Modnum(0, 0);
		long t = pow(10, a.len, mod);
		for(long i = a.len;i <= b.len;i++){
			long inf = i == a.len ? a.v : pow(10, i-1, mod);
//			long sup = i == b.len ? b.v : pow(10, i, mod)-1;
			long infe = i == a.len ? a.vx : powSafe(10, i-1, modx);
			long supe = i == b.len ? b.vx : powSafe(10, i, modx)-1;
//			if(sup < 0)sup += mod;
			if(supe < 0)supe += modx;

			long nume = supe-infe+1;
			if(nume < 0)nume += modx;
			long base = inf*sumGP(t, nume, mod)%mod;
			// 0 1 ... sup-inf

			nume %= modx;
			long mul = t;
			long B = mul;
			long s0 = 1;
			long s1 = 0;
			long res1 = 0;
			for(int d = 0;d < 63;d++){
				if(nume<<~d<0){
					res1 = (res1 * B + s1 + s0*((nume&(1L<<d)-1)%mod)) % mod;
				}
//				s1 = (s1 * (B+1) + (s0<<d)) % mod;
				s1 = (s1 * (B+1) + s0*((1L<<d)%mod)) % mod;
				s0 = s0 * (B+1) % mod;
				B = B * B % mod;
			}
			t = t * 10 % mod;

			ret = concat(ret, new Modnum((base+res1)%mod, i*(nume%emod)%emod));
		}
		return ret;
	}

	Modnum repeat(Modnum a, Modnum rep)
	{
		return new Modnum(
				sumGP(pow(10, a.len, mod), rep.vx, mod) * a.v % mod,
				a.len*(rep.vx%emod)%emod
				);
	}

	public static class Modnum
	{
		public long v;
		public long vx;
		public long len;
		public Modnum(long v, long len) {
			this.v = v;
			this.len = len;
		}
		public Modnum(long v, long len, long vx) {
			this.v = v;
			this.len = len;
			this.vx = vx;
		}
		@Override
		public String toString() {
			return "Datum [v=" + v + ", len=" + len + "]";
		}
	}

	public static long powSafe(long a, long n, long mod)
	{
//		a %= mod;
		long ret = 1; // 1%mod if mod=1,n=0
		int x = 63-Long.numberOfLeadingZeros(n);
		for(;x >= 0;x--){
			ret = mulEx(ret, ret, mod);
			if(n<<~x<0)ret = mulEx(ret, a, mod);
		}
		return ret;
	}

	public static long mul(long a, long b, long mod)
	{
		if(a >= mod || a < 0)a %= mod;
		if(a < 0)a += mod;
		if(b >= mod || b < 0)b %= mod;
		if(b < 0)b += mod;

		long ret = 0;
		int x = 63-Long.numberOfLeadingZeros(b);
		for(;x >= 0;x--){
			ret += ret;
			if(ret >= mod)ret -= mod;
			if(b<<~x<0){
				ret += a;
				if(ret >= mod)ret -= mod;
			}
		}
		return ret;
	}

	public static long mulEx(long a, long b, long mod)
	{
		if(a >= mod || a < 0)a %= mod;
		if(a < 0)a += mod;
		if(b >= mod || b < 0)b %= mod;
		if(b < 0)b += mod;

		long ret = 0;
		int x = 63-Long.numberOfLeadingZeros(b);
		for(;x >= 0;x--){
			ret += ret;
			if(Long.compareUnsigned(ret, mod) >= 0)ret -= mod;
			if(b<<~x<0){
				ret += a;
				if(Long.compareUnsigned(ret, mod) >= 0)ret -= mod;
			}
		}
		return ret;
	}

	public static long sumGP(long a, long n, long mod)
	{
		long smul = 1; // % mod
		long mul = a % mod;
		long ret = 0;
		for(;n > 0;n >>>= 1){
			if((n&1)==1){
				ret = (ret * mul + smul) % mod;
			}
			smul = smul * (mul + 1) % mod;
			mul = mul * mul % mod;
		}
		return ret;
	}

	public static long pow(long a, long n, long mod) {
		//		a %= mod;
		long ret = 1;
		int x = 63 - Long.numberOfLeadingZeros(n);
		for (; x >= 0; x--) {
			ret = ret * ret % mod;
			if (n << 63 - x < 0)
				ret = ret * a % mod;
		}
		return ret;
	}

	void run() throws Exception
	{
		is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		tr(System.currentTimeMillis()-s+"ms");
	}

	public static void main(String[] args) throws Exception { new F().run(); }

	private byte[] inbuf = new byte[1024];
	public int lenbuf = 0, ptrbuf = 0;

	private int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf){
			ptrbuf = 0;
			try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
	private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

	private double nd() { return Double.parseDouble(ns()); }
	private char nc() { return (char)skip(); }

	private String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n)
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while(p < n && !(isSpaceChar(b))){
			buf[p++] = (char)b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private char[][] nm(int n, int m)
	{
		char[][] map = new char[n][];
		for(int i = 0;i < n;i++)map[i] = ns(m);
		return map;
	}

	private int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}

	private int ni()
	{
		int num = 0, b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private long nl()
	{
		long num = 0;
		int b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
	private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author KharYusuf
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        FCoffeeVarietiesEasyVersion solver = new FCoffeeVarietiesEasyVersion();
        solver.solve(1, in, out);
        out.close();
    }

    static class FCoffeeVarietiesEasyVersion {
        public void solve(int testNumber, FastReader s, PrintWriter w) {
            int n = s.nextInt(), k = s.nextInt();
            int BL_SZ = k + 1 >> 1;
            boolean[] rep = new boolean[n];
            for (int i = 0; i < n; i++) if (query(i, s, w)) rep[i] = true;
            for (int i = 0; i < n; i += BL_SZ) {
                for (int j = i + BL_SZ; j < n; j += BL_SZ) {
                    reset(w);
                    for (int l = i, c = 0; c < BL_SZ; l++, c++) query(l, s, w);
                    for (int l = j, c = 0; c < BL_SZ; l++, c++) if (query(l, s, w)) rep[i] = true;
                }
            }
            int ans = 0;
            for (int i = 0; i < n; i++) if (!rep[i]) ans++;
            w.println(ans);
        }

        boolean query(int i, FastReader s, PrintWriter w) {
            w.println("? " + ++i);
            w.flush();
            return s.nextChar() == 'Y';
        }

        void reset(PrintWriter w) {
            w.println('R');
            w.flush();
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {

            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars) {

                curChar = 0;

                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (numChars <= 0)
                    return -1;
            }

            return buf[curChar++];
        }

        public int nextInt() {

            int c = read();

            while (isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();

                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public char nextChar() {

            int c = read();

            while (isSpaceChar(c))
                c = read();

            return (char) c;
        }

        public boolean isSpaceChar(int c) {

            if (filter != null)
                return filter.isSpaceChar(c);

            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author KharYusuf
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        FCoffeeVarietiesEasyVersion solver = new FCoffeeVarietiesEasyVersion();
        solver.solve(1, in, out);
        out.close();
    }

    static class FCoffeeVarietiesEasyVersion {
        public void solve(int testNumber, FastReader s, PrintWriter w) {
            int n = s.nextInt(), k = s.nextInt();
            int BL_SZ = k + 1 >> 1;
            boolean[] rep = new boolean[n];
            for (int i = 0; i < n; i++) if (query(i, s, w)) rep[i] = true;
            for (int i = 0; i < n; i += BL_SZ) {
                for (int j = i + BL_SZ; j < n; j += BL_SZ) {
                    reset(w);
                    for (int l = i, c = 0; c < BL_SZ; l++, c++) query(l, s, w);
                    for (int l = j, c = 0; c < BL_SZ; l++, c++) if (query(l, s, w)) rep[i] = true;
                }
            }
            int ans = 0;
            for (int i = 0; i < n; i++) if (!rep[i]) ans++;
            w.println(ans);
        }

        boolean query(int i, FastReader s, PrintWriter w) {
            w.println("? " + ++i);
            w.flush();
            return s.nextChar() == 'N';
        }

        void reset(PrintWriter w) {
            w.println('R');
            w.flush();
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {

            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars) {

                curChar = 0;

                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (numChars <= 0)
                    return -1;
            }

            return buf[curChar++];
        }

        public int nextInt() {

            int c = read();

            while (isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();

                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public char nextChar() {

            int c = read();

            while (isSpaceChar(c))
                c = read();

            return (char) c;
        }

        public boolean isSpaceChar(int c) {

            if (filter != null)
                return filter.isSpaceChar(c);

            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.PrintStream;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.ArrayList;
import java.io.InputStream;

import static java.lang.Math.*;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Coupon Kaka
 */
/*
    "Digits 1-9 in unit place is a myth, actual counting always has digit 0 in the unit place." - Coupon Kaka
*/
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        FCoffeeVarietiesEasyVersion solver = new FCoffeeVarietiesEasyVersion();
        solver.solve(1, in, out);
        out.close();
    }

    static class FCoffeeVarietiesEasyVersion {
        boolean isNew(int ind, InputReader sc) {
            System.out.println("? " + (ind + 1));
            System.out.flush();
            char ans = sc.next().charAt(0);
            if (ans == 'Y')
                return false;
            return true;
        }

        void reset() {
            System.out.println("R");
            System.out.flush();
        }

        public void solve(int testNumber, InputReader sc, PrintWriter out) {
            int n = sc.nextInt();
            int k = sc.nextInt();

            int flag[] = new int[n];
            ArrayList<Integer> list = new ArrayList<>();
            for (int i = 0; i < k; ++i) {
                if (isNew(i, sc)) {
                    flag[i] = 0;
                    list.add(i);
                } else
                    flag[i] = 1;
            }

            for (int i = k; i < n; i += (k + 1) / 2) {
                int l = i;
                int r = min(n - 1, i + ((k + 1) / 2) - 1);

                for (int j = 0; j < list.size(); j += (k + 1) / 2) {
                    reset();
                    for (int p = j; p < min(list.size(), j + ((k + 1) / 2)); ++p)
                        isNew(list.get(p), sc);
                    for (int p = l; p <= r; ++p) {
                        if (!isNew(p, sc))
                            flag[p] = 1;
                    }
                }

                for (int j = l; j <= r; ++j) {
                    if (flag[j] == 0)
                        list.add(j);
                }
            }

            System.out.println("! " + list.size());
            System.out.flush();
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();

            while (isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public String readString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            }
            while (!isSpaceChar(c));

            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            return readString();
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author KharYusuf
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        FCoffeeVarietiesEasyVersion solver = new FCoffeeVarietiesEasyVersion();
        solver.solve(1, in, out);
        out.close();
    }

    static class FCoffeeVarietiesEasyVersion {
        public void solve(int testNumber, FastReader s, PrintWriter w) {
            int n = s.nextInt(), k = s.nextInt();
            int BL_SZ = k + 1 >> 1;
            boolean[] rep = new boolean[n];
            for (int i = 0; i < n; i++) if (query(i, s, w)) rep[i] = true;
            for (int i = 0; i < n; i += BL_SZ) {
                for (int j = i + BL_SZ; j < n; j += BL_SZ) {
                    reset(w);
                    for (int l = i, c = 0; c < BL_SZ; l++, c++) query(l, s, w);
                    for (int l = j, c = 0; c < BL_SZ; l++, c++) if (query(l, s, w)) rep[l] = true;
                }
            }
            int ans = 0;
            for (int i = 0; i < n; i++) if (!rep[i]) ans++;
            w.println("! " + ans);
            w.flush();
        }

        boolean query(int i, FastReader s, PrintWriter w) {
            w.println("? " + ++i);
            w.flush();
            return s.nextChar() == 'Y';
        }

        void reset(PrintWriter w) {
            w.println('R');
            w.flush();
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {

            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars) {

                curChar = 0;

                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (numChars <= 0)
                    return -1;
            }

            return buf[curChar++];
        }

        public int nextInt() {

            int c = read();

            while (isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();

                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public char nextChar() {

            int c = read();

            while (isSpaceChar(c))
                c = read();

            return (char) c;
        }

        public boolean isSpaceChar(int c) {

            if (filter != null)
                return filter.isSpaceChar(c);

            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}


import java.io.*;
import java.util.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class cf1387a_2 {

    static int[] par;
    static boolean[] set;

    static int find(int i) {
        return i == par[i] ? i : (par[i] = find(par[i]));
    }

    static void union(int i, int j) {
        int a = find(i), b = find(j);
        if (a != b) {
            par[b] = a;
            set[a] |= set[b];
        }
    }

    public static void main(String[] args) throws IOException {
        int n = rni(), m = ni();
        par = new int[n];
        set = new boolean[n];
        for (int i = 0; i < n; ++i) {
            par[i] = i;
        }
        List<Map<Integer, Integer>> g = new ArrayList<>();
        double[] a = new double[n], b = new double[n];
        fill(a, -2);
        for (int i = 0; i < n; ++i) {
            g.add(new HashMap<>());
        }
        boolean invalid = false;
        for (int i = 0; i < m; ++i) {
            int aa = rni() - 1, bb = ni() - 1, c = ni();
            if (g.get(aa).containsKey(bb) && g.get(aa).get(bb) != c) {
                invalid = true;
            }
            union(aa, bb);
            g.get(aa).put(bb, c);
            g.get(bb).put(aa, c);
            if (aa == bb) {
                a[aa] = 0;
                b[aa] = (double) c / 2;
                set[find(aa)] = true;
            }
        }
        if (invalid) {
            prN();
            close();
            return;
        }
        List<List<Integer>> comps = new ArrayList<>();
        int ind = 0, map[] = new int[n];
        for (int i = 0; i < n; ++i) {
            if (i == par[i]) {
                map[i] = ind++;
                comps.add(new ArrayList<>());
            }
        }
        for (int i = 0; i < n; ++i) {
            comps.get(map[find(i)]).add(i);
        }
        boolean[] vis = new boolean[n];
        for (int i = 0; i < ind; ++i) {
            if (set[find(comps.get(i).get(0))]) {
                for (int j = 0, end = comps.get(i).size(); j < end; ++j) {
                    if (a[comps.get(i).get(j)] == 0) {
                        a[comps.get(i).get(j)] = 1;
                        if (!dfs(g, comps.get(i).get(j), a, b, vis, comps, map)) {
                            prN();
                            close();
                            return;
                        }
                        break;
                    }
                }
            } else {
                a[comps.get(i).get(0)] = 1;
                if (!dfs(g, comps.get(i).get(0), a, b, vis, comps, map)) {
                    prN();
                    close();
                    return;
                }
                if (a[comps.get(i).get(0)] != 0) {
                    // minimize
                    // h();
                    List<Double> median = new ArrayList<>();
                    for (int j = 0, end = comps.get(i).size(); j < end; ++j) {
                        median.add(-a[comps.get(i).get(j)] * b[comps.get(i).get(j)]);
                    }
                    median.sort(Double::compareTo);
                    double x = median.size() % 2 == 0 ? (median.get(median.size() / 2 - 1) + median.get(median.size() / 2)) / 2 : median.get(median.size() / 2);
                    // prln(a);
                    // prln(b);
                    // prln(x);
                    for (int j = 0, end = comps.get(i).size(); j < end; ++j) {
                        b[comps.get(i).get(j)] += a[comps.get(i).get(j)] * x;
                    }
                }
            }
        }
        prY();
        prln(b);
        close();
    }

    static boolean dfs(List<Map<Integer, Integer>> g, int i, double[] a, double[] b, boolean[] vis, List<List<Integer>> comps, int[] map) {
        // prln(i, a[i], b[i]);
        vis[i] = true;
        for (int k : g.get(i).keySet()) {
            double a_prime = -a[i], b_prime = g.get(i).get(k) - b[i];
            // pr("\t");
            // prln(i, k, b_prime);
            if (vis[k]) {
                if (abs(a_prime - a[k]) < 1e-6) {
                    if (abs(b_prime - b[k]) > 1e-6) {
                        return false;
                    }
                } else {
                    // h();
                    double x = (b[k] - b_prime) / (a_prime - a[k]);
                    for (int j : comps.get(map[find(i)])) {
                        if (vis[j]) {
                            b[j] += a[j] * x;
                            a[j] = 0;
                        }
                    }
                }
            } else {
                a[k] = a_prime;
                b[k] = b_prime;
                if (!dfs(g, k, a, b, vis, comps, map)) {
                    return false;
                }
            }
        }
        return true;
    }

    static BufferedReader __in = new BufferedReader(new InputStreamReader(System.in));
    static PrintWriter __out = new PrintWriter(new OutputStreamWriter(System.out));
    static StringTokenizer input;
    static Random __rand = new Random();

    // references
    // IBIG = 1e9 + 7
    // IMAX ~= 2e9
    // LMAX ~= 9e18

    // constants
    static final int IBIG = 1000000007;
    static final int IMAX = 2147483647;
    static final int IMIN = -2147483648;
    static final long LMAX = 9223372036854775807L;
    static final long LMIN = -9223372036854775808L;
    // math util
    static int minof(int a, int b, int c) {return min(a, min(b, c));}
    static int minof(int... x) {if (x.length == 1) return x[0]; if (x.length == 2) return min(x[0], x[1]); if (x.length == 3) return min(x[0], min(x[1], x[2])); int min = x[0]; for (int i = 1; i < x.length; ++i) if (x[i] < min) min = x[i]; return min;}
    static long minof(long a, long b, long c) {return min(a, min(b, c));}
    static long minof(long... x) {if (x.length == 1) return x[0]; if (x.length == 2) return min(x[0], x[1]); if (x.length == 3) return min(x[0], min(x[1], x[2])); long min = x[0]; for (int i = 1; i < x.length; ++i) if (x[i] < min) min = x[i]; return min;}
    static int maxof(int a, int b, int c) {return max(a, max(b, c));}
    static int maxof(int... x) {if (x.length == 1) return x[0]; if (x.length == 2) return max(x[0], x[1]); if (x.length == 3) return max(x[0], max(x[1], x[2])); int max = x[0]; for (int i = 1; i < x.length; ++i) if (x[i] > max) max = x[i]; return max;}
    static long maxof(long a, long b, long c) {return max(a, max(b, c));}
    static long maxof(long... x) {if (x.length == 1) return x[0]; if (x.length == 2) return max(x[0], x[1]); if (x.length == 3) return max(x[0], max(x[1], x[2])); long max = x[0]; for (int i = 1; i < x.length; ++i) if (x[i] > max) max = x[i]; return max;}
    static int powi(int a, int b) {if (a == 0) return 0; int ans = 1; while (b > 0) {if ((b & 1) > 0) ans *= a; a *= a; b >>= 1;} return ans;}
    static long powl(long a, int b) {if (a == 0) return 0; long ans = 1; while (b > 0) {if ((b & 1) > 0) ans *= a; a *= a; b >>= 1;} return ans;}
    static int fli(double d) {return (int) d;}
    static int cei(double d) {return (int) ceil(d);}
    static long fll(double d) {return (long) d;}
    static long cel(double d) {return (long) ceil(d);}
    static int gcf(int a, int b) {return b == 0 ? a : gcf(b, a % b);}
    static long gcf(long a, long b) {return b == 0 ? a : gcf(b, a % b);}
    static int lcm(int a, int b) {return a * b / gcf(a, b);}
    static long lcm(long a, long b) {return a * b / gcf(a, b);}
    static int randInt(int min, int max) {return __rand.nextInt(max - min + 1) + min;}
    static long mix(long x) {x += 0x9e3779b97f4a7c15L; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9L; x = (x ^ (x >> 27)) * 0x94d049bb133111ebL; return x ^ (x >> 31);}
    // array util
    static void reverse(int[] a) {for (int i = 0, n = a.length, half = n / 2; i < half; ++i) {int swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap;}}
    static void reverse(long[] a) {for (int i = 0, n = a.length, half = n / 2; i < half; ++i) {long swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap;}}
    static void reverse(double[] a) {for (int i = 0, n = a.length, half = n / 2; i < half; ++i) {double swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap;}}
    static void reverse(char[] a) {for (int i = 0, n = a.length, half = n / 2; i < half; ++i) {char swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap;}}
    static void shuffle(int[] a) {int n = a.length - 1; for (int i = 0; i < n; ++i) {int ind = randInt(i, n); int swap = a[i]; a[i] = a[ind]; a[ind] = swap;}}
    static void shuffle(long[] a) {int n = a.length - 1; for (int i = 0; i < n; ++i) {int ind = randInt(i, n); long swap = a[i]; a[i] = a[ind]; a[ind] = swap;}}
    static void shuffle(double[] a) {int n = a.length - 1; for (int i = 0; i < n; ++i) {int ind = randInt(i, n); double swap = a[i]; a[i] = a[ind]; a[ind] = swap;}}
    static void rsort(int[] a) {shuffle(a); sort(a);}
    static void rsort(long[] a) {shuffle(a); sort(a);}
    static void rsort(double[] a) {shuffle(a); sort(a);}
    static int[] copy(int[] a) {int[] ans = new int[a.length]; for (int i = 0; i < a.length; ++i) ans[i] = a[i]; return ans;}
    static long[] copy(long[] a) {long[] ans = new long[a.length]; for (int i = 0; i < a.length; ++i) ans[i] = a[i]; return ans;}
    static double[] copy(double[] a) {double[] ans = new double[a.length]; for (int i = 0; i < a.length; ++i) ans[i] = a[i]; return ans;}
    static char[] copy(char[] a) {char[] ans = new char[a.length]; for (int i = 0; i < a.length; ++i) ans[i] = a[i]; return ans;}
    // graph util
    static List<List<Integer>> g(int n) {List<List<Integer>> g = new ArrayList<>(); for (int i = 0; i < n; ++i) g.add(new ArrayList<>()); return g;}
    static List<Set<Integer>> sg(int n) {List<Set<Integer>> g = new ArrayList<>(); for (int i = 0; i < n; ++i) g.add(new HashSet<>()); return g;}
    static void c(List<? extends Collection<Integer>> g, int u, int v) {g.get(u).add(v); g.get(v).add(u);}
    static void cto(List<? extends Collection<Integer>> g, int u, int v) {g.get(u).add(v);}
    static void dc(List<? extends Collection<Integer>> g, int u, int v) {g.get(u).remove(v); g.get(v).remove(u);}
    static void dcto(List<? extends Collection<Integer>> g, int u, int v) {g.get(u).remove(v);}
    // input
    static void r() throws IOException {input = new StringTokenizer(rline());}
    static int ri() throws IOException {return Integer.parseInt(rline());}
    static long rl() throws IOException {return Long.parseLong(rline());}
    static double rd() throws IOException {return Double.parseDouble(rline());}
    static int[] ria(int n) throws IOException {int[] a = new int[n]; r(); for (int i = 0; i < n; ++i) a[i] = ni(); return a;}
    static int[] riam1(int n) throws IOException {int[] a = new int[n]; r(); for (int i = 0; i < n; ++i) a[i] = ni() - 1; return a;}
    static long[] rla(int n) throws IOException {long[] a = new long[n]; r(); for (int i = 0; i < n; ++i) a[i] = nl(); return a;}
    static double[] rda(int n) throws IOException {double[] a = new double[n]; r(); for (int i = 0; i < n; ++i) a[i] = nd(); return a;}
    static char[] rcha() throws IOException {return rline().toCharArray();}
    static String rline() throws IOException {return __in.readLine();}
    static String n() {return input.nextToken();}
    static int rni() throws IOException {r(); return ni();}
    static int ni() {return Integer.parseInt(n());}
    static long rnl() throws IOException {r(); return nl();}
    static long nl() {return Long.parseLong(n());}
    static double rnd() throws IOException {r(); return nd();}
    static double nd() {return Double.parseDouble(n());}
    static List<List<Integer>> rg(int n, int m) throws IOException {List<List<Integer>> g = g(n); for (int i = 0; i < m; ++i) c(g, rni() - 1, ni() - 1); return g;}
    static void rg(List<List<Integer>> g, int m) throws IOException {for (int i = 0; i < m; ++i) c(g, rni() - 1, ni() - 1);}
    static List<List<Integer>> rdg(int n, int m) throws IOException {List<List<Integer>> g = g(n); for (int i = 0; i < m; ++i) cto(g, rni() - 1, ni() - 1); return g;}
    static void rdg(List<List<Integer>> g, int m) throws IOException {for (int i = 0; i < m; ++i) cto(g, rni() - 1, ni() - 1);}
    static List<Set<Integer>> rsg(int n, int m) throws IOException {List<Set<Integer>> g = sg(n); for (int i = 0; i < m; ++i) c(g, rni() - 1, ni() - 1); return g;}
    static void rsg(List<Set<Integer>> g, int m) throws IOException {for (int i = 0; i < m; ++i) c(g, rni() - 1, ni() - 1);}
    static List<Set<Integer>> rdsg(int n, int m) throws IOException {List<Set<Integer>> g = sg(n); for (int i = 0; i < m; ++i) cto(g, rni() - 1, ni() - 1); return g;}
    static void rdsg(List<Set<Integer>> g, int m) throws IOException {for (int i = 0; i < m; ++i) cto(g, rni() - 1, ni() - 1);}
    // output
    static void pr(int i) {__out.print(i);}
    static void prln(int i) {__out.println(i);}
    static void pr(long l) {__out.print(l);}
    static void prln(long l) {__out.println(l);}
    static void pr(double d) {__out.print(d);}
    static void prln(double d) {__out.println(d);}
    static void pr(char c) {__out.print(c);}
    static void prln(char c) {__out.println(c);}
    static void pr(char[] s) {__out.print(new String(s));}
    static void prln(char[] s) {__out.println(new String(s));}
    static void pr(String s) {__out.print(s);}
    static void prln(String s) {__out.println(s);}
    static void pr(Object o) {__out.print(o);}
    static void prln(Object o) {__out.println(o);}
    static void prln() {__out.println();}
    static void pryes() {prln("yes");}
    static void pry() {prln("Yes");}
    static void prY() {prln("YES");}
    static void prno() {prln("no");}
    static void prn() {prln("No");}
    static void prN() {prln("NO");}
    static void pryesno(boolean b) {prln(b ? "yes" : "no");};
    static void pryn(boolean b) {prln(b ? "Yes" : "No");}
    static void prYN(boolean b) {prln(b ? "YES" : "NO");}
    static void prln(int... a) {for (int i = 0, len = a.length - 1; i < len; pr(a[i]), pr(' '), ++i); if (a.length > 0) prln(a[a.length - 1]); else prln();}
    static void prln(long... a) {for (int i = 0, len = a.length - 1; i < len; pr(a[i]), pr(' '), ++i); if (a.length > 0) prln(a[a.length - 1]); else prln();}
    static void prln(double... a) {for (int i = 0, len = a.length - 1; i < len; pr(a[i]), pr(' '), ++i); if (a.length > 0) prln(a[a.length - 1]); else prln();}
    static <T> void prln(Collection<T> c) {int n = c.size() - 1; Iterator<T> iter = c.iterator(); for (int i = 0; i < n; pr(iter.next()), pr(' '), ++i); if (n >= 0) prln(iter.next()); else prln();}
    static void h() {prln("hlfd"); flush();}
    static void flush() {__out.flush();}
    static void close() {__out.close();}}


import java.io.*; import java.util.*;
public class Graph {

    public static void main(String[] args) throws IOException {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer(br.readLine());
        int N=Integer.parseInt(st.nextToken());
        int M=Integer.parseInt(st.nextToken());
        ArrayList<Integer> arl[]=new ArrayList[N];
        for (int i = 0; i < N; i++) {
            arl[i]=new ArrayList<>();
        }
        int a,b,vv;
        for (int i = 0; i < M; i++) {
            st=new StringTokenizer(br.readLine());
            a=Integer.parseInt(st.nextToken())-1;
            b=Integer.parseInt(st.nextToken())-1;
            vv=Integer.parseInt(st.nextToken());
            arl[a].add(4*b+2*vv); arl[b].add(4*a+2*vv);
        }

        boolean[] vis=new boolean[N];

        int[] m=new int[N];
        int[] c=new int[N];
        int done=0; int pt=0;
        while(done<N){
            while(pt<N && vis[pt]){
                pt++;
            }

            //Start DFS at pt, finish the component
            m[pt]=1; //b[pt]=0
            Queue<Integer> qu=new LinkedList<>();
            qu.add(pt); vis[pt]=true; done++;
            Queue<Integer> qu2=new LinkedList<>();//Tracks all vertices in the queue
            qu2.add(pt); boolean fix=false;
            int x,y;
            while(!qu.isEmpty()){
                int v=qu.poll();
                for (int p : arl[v]) {
                    x=4-p%4; y=(p-x)/4;
                    if(!vis[y]){
                        vis[y]=true; qu.add(y);
                        if(!fix){
                            qu2.add(y);
                        }
                        m[y]=-m[v]; c[y]=x-c[v]; done++;
                    }else{
                        //System.out.println(x+" "+y+" "+v);
                        if(m[y]==m[v] && m[v]!=0){
                            //m[p.vtx]x+c[p.vtx]+m[v]x+c[v] is known
                            int xx=(x-c[y]-c[v])/(2*m[y]); fix=true;

                            for(int vtx: qu2){

                                c[vtx]+=m[vtx]*xx; m[vtx]=0;
                            }
                        }else if(m[y]+m[v]==0){//m[v]=0
                            if(c[y]+c[v]!=x){
                                System.out.println("NO"); return;
                            }
                        }
                    }
                }
                //System.out.println(Arrays.toString(m));
                //System.out.println(Arrays.toString(c));
            }

            if(m[pt]!=0){//This component is not fixed
                ArrayList<Integer> arl2=new ArrayList<>();

                for (int i : qu2) {
                    if(m[i]<0){
                        m[i]=-m[i]; c[i]=-c[i]; qu.add(i);
                    }
                    arl2.add(c[i]);
                }

                Collections.sort(arl2);
                int med=arl2.get(arl2.size()/2);
                for (int i : qu2) {
                    c[i]-=med;

                }
                while(!qu.isEmpty()){
                    int i=qu.poll();
                    c[i]=-c[i];
                }
            }

        }
        System.out.println("YES");
        StringBuilder sb=new StringBuilder();
        for (int i = 0; i < N; i++) {
             sb.append((double)c[i]/2).append(" ");
        }
        System.out.println(sb.toString());
    }

}


import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
	static final double TOL = 0.000001;
	static ArrayList<Edge>[] graph;
	static int[][] nodes;
	static boolean[] vis;

	static HashSet<Integer> unusedEdges;
	static ArrayList<Integer> visited;
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter pw = new PrintWriter(System.out);

		int N = sc.ni();
		int M = sc.ni();
		vis = new boolean[N];
		graph = new ArrayList[N];
		for (int i = 0; i < N; i++) {
			graph[i] = new ArrayList<Edge>();
		}
		int[][] edges = new int[M][3];
		for (int i = 0; i < M; i++) {
			int n1 = sc.ni()-1;
			int n2 = sc.ni()-1;
			int s = sc.ni();
			edges[i] = new int[] {n1,n2,s};
			graph[n1].add(new Edge(n2,s,i));
			graph[n2].add(new Edge(n1,s,i));
		}
		nodes = new int[N][2]; //{m,b} m(x)+b
		for (int i = 0; i < N; i++)
			nodes[i][0] = Integer.MAX_VALUE;

		double[] ans = new double[N];

		for (int n = 0; n < N; n++) {
			if (nodes[n][0]<Integer.MAX_VALUE)
				continue;
			nodes[n][0] = 1;
			unusedEdges = new HashSet<Integer>();
			visited = new ArrayList<Integer>();
			visited.add(n);
			vis[n] = true;
			usedDFS(n);
			dfs(n);
			double x = Double.MAX_VALUE;
			for (int idx: unusedEdges) {
				int i = edges[idx][0];
				int j = edges[idx][1];
				int sum = edges[idx][2];
				int m = nodes[i][0]+nodes[j][0];
				int eq = sum-(nodes[i][1]+nodes[j][1]);
				if (m != 0) {
					//the value of x is uniquely determined!!!
					double val = (0.0+eq)/m;
					if (x == Double.MAX_VALUE) {
						x = val;
					} else if (Math.abs(x-val) > TOL) {
						pw.println("NO");
						pw.close();
						return;
					}
				} else if (Math.abs(eq) > TOL) {
					pw.println("NO");
					pw.close();
					return;
				}
			}

			if (x == Double.MAX_VALUE) {
				ArrayList<Double> meds = new ArrayList<Double>();
				for (int i: visited) {
					if (nodes[i][0] != 0) {
						meds.add((0.0-nodes[i][1])/nodes[i][0]);
					}
				}
				Collections.sort(meds);
				x = meds.get(meds.size()/2);
			}
			for (int i: visited) {
				ans[i] = nodes[i][0]*x+nodes[i][1];
			}
		}

		pw.println("YES");
		for (double d: ans)
			pw.print(d + " ");
		pw.close();
	}

	static void usedDFS(int node) {
		for (Edge e: graph[node]) {
			int c = e.to;
			unusedEdges.add(e.idx);
			if (!vis[c]) {
				vis[c] = true;
				visited.add(c);
				usedDFS(c);
			}
		}
	}

	static void dfs(int node) {
		for (Edge e: graph[node]) {
			int c = e.to;
			if (nodes[c][0]==Integer.MAX_VALUE) {
				nodes[c][0] = -1*nodes[node][0];
				nodes[c][1] = e.sum-nodes[node][1];
				unusedEdges.remove(e.idx);
				dfs(c);
			}
		}
	}

	static class Edge {
		int to;
		int sum;
		int idx;
		public Edge (int t, int s, int i) {
			to = t;
			sum = s;
			idx = i;
		}
	}

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException  e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int ni() {
            return Integer.parseInt(next());
        }

        long nl() {
            return Long.parseLong(next());
        }

        double nd() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class cf1387a {

    public static void main(String[] args) throws Exception {
        int num = 998244353;

        // TODO Auto-generated method stub
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        StringTokenizer st = new StringTokenizer(bf.readLine());
        int n = Integer.parseInt(st.nextToken());
        int m = Integer.parseInt(st.nextToken());
        Map<Integer, Map<Integer, Integer>> graph = new HashMap<Integer, Map<Integer, Integer>>();
        boolean ans = true;
        for (int i = 1; i <= n; i++) {
            graph.put(i, new HashMap<Integer, Integer>());
        }
        for (int i = 0; i < m; i++) {
            StringTokenizer st1 = new StringTokenizer(bf.readLine());
            int a = Integer.parseInt(st1.nextToken());
            int b = Integer.parseInt(st1.nextToken());
            int c = Integer.parseInt(st1.nextToken());
            if (graph.get(a).containsKey(b) && graph.get(a).get(b) != c)
                ans = false;
            else
                graph.get(a).put(b, c);
            if (graph.get(b).containsKey(a) && graph.get(b).get(a) != c)
                ans = false;
            else
                graph.get(b).put(a, c);
        }
        Set<Integer> seen = new HashSet<Integer>();
        int[][] coefficients = new int[n + 1][2]; //[0] is the coefficient of x^0, [1] is coefficient of x^1
        double[] assign = new double[n + 1];
        for (int i = 1; i <= n; i++) {
            if (!seen.contains(i)) {
                coefficients[i][1] = 1;
                seen.add(1);
                double x = Integer.MAX_VALUE;
                Queue<Integer> bfs = new LinkedList<Integer>();
                bfs.add(i);
                Set<Integer> tempseen = new HashSet<Integer>();
                tempseen.add(i);
                while (!bfs.isEmpty()) {
                    int vertex = bfs.remove();
                    for (int k : graph.get(vertex).keySet()) {
                        if (!seen.contains(k)) {
                            bfs.add(k);
                            coefficients[k][1] = 0 - coefficients[vertex][1];
                            coefficients[k][0] = graph.get(vertex).get(k) - coefficients[vertex][0];
                            tempseen.add(k);
                            seen.add(k);
                        } else {
                            int sum = graph.get(vertex).get(k);
                            if (coefficients[k][1] + coefficients[vertex][1] == 0 && coefficients[k][0] + coefficients[vertex][0] != sum)
                                ans = false;
                            else if (coefficients[k][1] + coefficients[vertex][1] != 0) {
                                double ass = (sum - coefficients[k][0] - coefficients[vertex][0] + 0.0) / (coefficients[k][1] + coefficients[vertex][1] + 0.0);
                                if (x != ass && x != Integer.MAX_VALUE)
                                    ans = false;
                                else
                                    x = ass;
                            }
                        }
                    }
                }
                if (x != Integer.MAX_VALUE) {
                    for (int j : tempseen) {
                        assign[j] = x * coefficients[j][1] + coefficients[j][0];
                    }
                } else {
                    int sumcoeff0 = 0;
                    int sumcoeff1 = 0;
                    int maxval = Integer.MIN_VALUE;
                    int minval = Integer.MAX_VALUE;
                    ArrayList<Integer> vals = new ArrayList<Integer>();
                    for (int j : tempseen) {
                        sumcoeff0 += coefficients[j][0];
                        sumcoeff1 += coefficients[j][1];
                        vals.add((0 - coefficients[j][1]) * coefficients[j][0]);
                    }
                    Collections.sort(vals);
                    if (vals.size() % 2 == 1) {
                        x = vals.get(vals.size() / 2);
                    } else {
                        x = (vals.get(vals.size() / 2) + vals.get(vals.size() / 2 - 1)) / 2.0;
                    }
                    for (int j : tempseen) {
                        assign[j] = x * coefficients[j][1] + coefficients[j][0];
                    }
                }

            }
        }

        if (!ans)
            out.println("NO");
        else {
            out.println("YES");
            for (int i = 1; i <= n; i++) {
                out.print(assign[i] + " ");
            }

        }

        out.println();

        out.close();

    }
}

//StringJoiner sj = new StringJoiner(" ");
//sj.add(strings)
//sj.toString() gives string of those stuff w spaces or whatever that sequence is


import java.io.*;
import java.math.*;
import java.util.*;
import java.util.stream.*;

public class H {

	boolean solve() {
		int alph = nextInt();
		int n = nextInt();

		int[][] a = new int[n][];
		int tot = 0;
		for (int i = 0; i < n; i++) {
			int k = nextInt();
			int[] che = a[i] = new int[k];
			for (int j = 0; j < k; j++) {
				che[j] = nextInt() - 1;
			}
			tot += k;
		}

		int r = (int) Math.sqrt(tot);
//		int r = Integer.MAX_VALUE;

		for (int i = 0, j = n - 1;;) {
			while (i < j && a[i].length <= r) {
				i++;
			}
			while (i < j && a[j].length > r) {
				j--;
			}
			if (i == j) {
				break;
			}

			int[] tmp = a[i];
			a[i] = a[j];
			a[j] = tmp;
		}

		HashMap<Long, Integer> map = new HashMap<>();
		for (int i = 0; i < n; i++) {
			int[] b = a[i];
//			if (b.length > r) {
			if (true) {
				continue;
			}
			for (int j1 = 0; j1 < b.length; j1++) {
				for (int j2 = j1 + 1; j2 < b.length; j2++) {
					long key = (long) b[j1] * alph + b[j2];
					Integer prev = map.get(key);
					if (prev == null) {
						map.put(key, b[j1 + 1]);
					} else if (prev != b[j1 + 1]) {
						return true;
					}
				}
			}
		}

		int[] id = new int[alph];
		Arrays.fill(id, -2);

		for (int i = 0; i < n; i++) {
			int[] b = a[i];
			if (b.length <= r) {
				break;
			}
			for (int j = 0; j < b.length; j++) {
				id[b[j]] = j;
			}

			for (int j = i + 1; j < n; j++) {
				if (clash(a[j], id)) {
					return true;
				}
			}

			for (int j = 0; j < b.length; j++) {
				id[b[j]] = -2;
			}
		}

		return false;
	}

	boolean clash(int[] a, int[] f) {
		int prev = f[a[0]];
		int curMin = prev == -2 ? Integer.MAX_VALUE : prev;
		for (int i = 1; i < a.length; i++) {
			int now = f[a[i]];
			if (now != prev + 1 && now > curMin) {
				return true;
			}
			if (now != -2) {
				curMin = Math.min(curMin, now);
			}

			prev = now;
		}
		return false;
	}

	void submit() {
		int t = nextInt();
		while (t-- > 0) {
			out.println(solve() ? "Human" : "Robot");
		}
	}

	void test() {

	}

	void stress() {
		for (int tst = 0;; tst++) {
			if (false) {
				throw new AssertionError();
			}
			System.err.println(tst);
		}
	}

	H() throws IOException {
		is = System.in;
		out = new PrintWriter(System.out);
		submit();
		// stress();
		// test();
		out.close();
	}

	static final Random rng = new Random();
	static final int C = 5;

	static int rand(int l, int r) {
		return l + rng.nextInt(r - l + 1);
	}

	public static void main(String[] args) throws IOException {
		new H();
	}

	private InputStream is;
	PrintWriter out;

	private byte[] buf = new byte[1 << 14];
	private int bufSz = 0, bufPtr = 0;

	private int readByte() {
		if (bufSz == -1)
			throw new RuntimeException("Reading past EOF");
		if (bufPtr >= bufSz) {
			bufPtr = 0;
			try {
				bufSz = is.read(buf);
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
			if (bufSz <= 0)
				return -1;
		}
		return buf[bufPtr++];
	}

	private boolean isTrash(int c) {
		return c < 33 || c > 126;
	}

	private int skip() {
		int b;
		while ((b = readByte()) != -1 && isTrash(b))
			;
		return b;
	}

	String nextToken() {
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while (!isTrash(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	String nextString() {
		int b = readByte();
		StringBuilder sb = new StringBuilder();
		while (!isTrash(b) || b == ' ') {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	double nextDouble() {
		return Double.parseDouble(nextToken());
	}

	char nextChar() {
		return (char) skip();
	}

	int nextInt() {
		int ret = 0;
		int b = skip();
		if (b != '-' && (b < '0' || b > '9')) {
			throw new InputMismatchException();
		}
		boolean neg = false;
		if (b == '-') {
			neg = true;
			b = readByte();
		}
		while (true) {
			if (b >= '0' && b <= '9') {
				ret = ret * 10 + (b - '0');
			} else {
				if (b != -1 && !isTrash(b)) {
					throw new InputMismatchException();
				}
				return neg ? -ret : ret;
			}
			b = readByte();
		}
	}

	long nextLong() {
		long ret = 0;
		int b = skip();
		if (b != '-' && (b < '0' || b > '9')) {
			throw new InputMismatchException();
		}
		boolean neg = false;
		if (b == '-') {
			neg = true;
			b = readByte();
		}
		while (true) {
			if (b >= '0' && b <= '9') {
				ret = ret * 10 + (b - '0');
			} else {
				if (b != -1 && !isTrash(b)) {
					throw new InputMismatchException();
				}
				return neg ? -ret : ret;
			}
			b = readByte();
		}
	}
}


import java.io.*;
import java.math.*;
import java.util.*;
import java.util.stream.*;

public class H {

	boolean solve() {
		int alph = nextInt();
		int n = nextInt();

		int[][] a = new int[n][];
		int tot = 0;
		for (int i = 0; i < n; i++) {
			int k = nextInt();
			int[] che = a[i] = new int[k];
			for (int j = 0; j < k; j++) {
				che[j] = nextInt() - 1;
			}
			tot += k;
		}

		int r = (int) Math.sqrt(tot);

		for (int i = 0, j = n - 1;;) {
			while (i < j && a[i].length <= r) {
				i++;
			}
			while (i < j && a[j].length > r) {
				j--;
			}
			if (i == j) {
				break;
			}

			int[] tmp = a[i];
			a[i] = a[j];
			a[j] = tmp;
		}

		HashMap<Long, Integer> map = new HashMap<>();
		for (int i = 0; i < n; i++) {
			int[] b = a[i];
			if (b.length > r) {
				continue;
			}
			for (int j1 = 0; j1 < b.length; j1++) {
				for (int j2 = j1 + 1; j2 < b.length; j2++) {
					long key = (long) b[j1] * alph + b[j2];
					Integer prev = map.get(key);
					if (prev == null) {
						map.put(key, b[j1 + 1]);
					} else if (prev != b[j1 + 1]) {
						return true;
					}
				}
			}
		}

		int[] id = new int[alph];
		Arrays.fill(id, -2);

		for (int i = 0; i < n; i++) {
			int[] b = a[i];
			if (b.length <= r) {
				break;
			}
			for (int j = 0; j < b.length; j++) {
				id[b[j]] = j;
			}

			for (int j = i + 1; j < n; j++) {
				if (clash(a[j], id)) {
					return true;
				}
			}

			for (int j = 0; j < b.length; j++) {
				id[b[j]] = -2;
			}
		}

		return false;
	}

	boolean clash(int[] a, int[] f) {
		int prev = f[a[0]];
		int curMin = prev == -1 ? Integer.MAX_VALUE : prev;
		for (int i = 1; i < a.length; i++) {
			int now = f[a[i]];
			if (now != prev + 1 && now > curMin) {
				return true;
			}
			if (now != -2) {
				curMin = Math.min(curMin, now);
			}

			prev = now;
		}
		return false;
	}

	void submit() {
		int t = nextInt();
		while (t-- > 0) {
			out.println(solve() ? "Human" : "Robot");
		}
	}

	void test() {

	}

	void stress() {
		for (int tst = 0;; tst++) {
			if (false) {
				throw new AssertionError();
			}
			System.err.println(tst);
		}
	}

	H() throws IOException {
		is = System.in;
		out = new PrintWriter(System.out);
		submit();
		// stress();
		// test();
		out.close();
	}

	static final Random rng = new Random();
	static final int C = 5;

	static int rand(int l, int r) {
		return l + rng.nextInt(r - l + 1);
	}

	public static void main(String[] args) throws IOException {
		new H();
	}

	private InputStream is;
	PrintWriter out;

	private byte[] buf = new byte[1 << 14];
	private int bufSz = 0, bufPtr = 0;

	private int readByte() {
		if (bufSz == -1)
			throw new RuntimeException("Reading past EOF");
		if (bufPtr >= bufSz) {
			bufPtr = 0;
			try {
				bufSz = is.read(buf);
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
			if (bufSz <= 0)
				return -1;
		}
		return buf[bufPtr++];
	}

	private boolean isTrash(int c) {
		return c < 33 || c > 126;
	}

	private int skip() {
		int b;
		while ((b = readByte()) != -1 && isTrash(b))
			;
		return b;
	}

	String nextToken() {
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while (!isTrash(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	String nextString() {
		int b = readByte();
		StringBuilder sb = new StringBuilder();
		while (!isTrash(b) || b == ' ') {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	double nextDouble() {
		return Double.parseDouble(nextToken());
	}

	char nextChar() {
		return (char) skip();
	}

	int nextInt() {
		int ret = 0;
		int b = skip();
		if (b != '-' && (b < '0' || b > '9')) {
			throw new InputMismatchException();
		}
		boolean neg = false;
		if (b == '-') {
			neg = true;
			b = readByte();
		}
		while (true) {
			if (b >= '0' && b <= '9') {
				ret = ret * 10 + (b - '0');
			} else {
				if (b != -1 && !isTrash(b)) {
					throw new InputMismatchException();
				}
				return neg ? -ret : ret;
			}
			b = readByte();
		}
	}

	long nextLong() {
		long ret = 0;
		int b = skip();
		if (b != '-' && (b < '0' || b > '9')) {
			throw new InputMismatchException();
		}
		boolean neg = false;
		if (b == '-') {
			neg = true;
			b = readByte();
		}
		while (true) {
			if (b >= '0' && b <= '9') {
				ret = ret * 10 + (b - '0');
			} else {
				if (b != -1 && !isTrash(b)) {
					throw new InputMismatchException();
				}
				return neg ? -ret : ret;
			}
			b = readByte();
		}
	}
}


import java.io.*;
import java.math.*;
import java.util.*;
import java.util.stream.*;

public class H {

	boolean solve() {
		int alph = nextInt();
		int n = nextInt();

		int[][] a = new int[n][];
		int tot = 0;
		for (int i = 0; i < n; i++) {
			int k = nextInt();
			int[] che = a[i] = new int[k];
			for (int j = 0; j < k; j++) {
				che[j] = nextInt() - 1;
			}
			tot += k;
		}

//		int r = (int) Math.sqrt(tot);
		int r = 0;

		for (int i = 0, j = n - 1;;) {
			while (i < j && a[i].length <= r) {
				i++;
			}
			while (i < j && a[j].length > r) {
				j--;
			}
			if (i == j) {
				break;
			}

			int[] tmp = a[i];
			a[i] = a[j];
			a[j] = tmp;
		}

		HashMap<Long, Integer> map = new HashMap<>();
		for (int i = 0; i < n; i++) {
			int[] b = a[i];
			if (b.length > r) {
				continue;
			}
			for (int j1 = 0; j1 < b.length; j1++) {
				for (int j2 = j1 + 1; j2 < b.length; j2++) {
					long key = (long) b[j1] * alph + b[j2];
					Integer prev = map.get(key);
					if (prev == null) {
						map.put(key, b[j1 + 1]);
					} else if (prev != b[j1 + 1]) {
						return true;
					}
				}
			}
		}

		int[] id = new int[alph];
		Arrays.fill(id, -2);

		for (int i = 0; i < n; i++) {
			int[] b = a[i];
			if (b.length <= r) {
				break;
			}
			for (int j = 0; j < b.length; j++) {
				id[b[j]] = j;
			}

			for (int j = i + 1; j < n; j++) {
				if (clash(a[j], id)) {
					return true;
				}
			}

			for (int j = 0; j < b.length; j++) {
				id[b[j]] = -2;
			}
		}

		return false;
	}

	boolean clash(int[] a, int[] f) {
		int prev = f[a[0]];
		int curMin = prev == -1 ? Integer.MAX_VALUE : prev;
		for (int i = 1; i < a.length; i++) {
			int now = f[a[i]];
			if (now != prev + 1 && now > curMin) {
				return true;
			}
			if (now != -2) {
				curMin = Math.min(curMin, now);
			}

			prev = now;
		}
		return false;
	}

	void submit() {
		int t = nextInt();
		while (t-- > 0) {
			out.println(solve() ? "Human" : "Robot");
		}
	}

	void test() {

	}

	void stress() {
		for (int tst = 0;; tst++) {
			if (false) {
				throw new AssertionError();
			}
			System.err.println(tst);
		}
	}

	H() throws IOException {
		is = System.in;
		out = new PrintWriter(System.out);
		submit();
		// stress();
		// test();
		out.close();
	}

	static final Random rng = new Random();
	static final int C = 5;

	static int rand(int l, int r) {
		return l + rng.nextInt(r - l + 1);
	}

	public static void main(String[] args) throws IOException {
		new H();
	}

	private InputStream is;
	PrintWriter out;

	private byte[] buf = new byte[1 << 14];
	private int bufSz = 0, bufPtr = 0;

	private int readByte() {
		if (bufSz == -1)
			throw new RuntimeException("Reading past EOF");
		if (bufPtr >= bufSz) {
			bufPtr = 0;
			try {
				bufSz = is.read(buf);
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
			if (bufSz <= 0)
				return -1;
		}
		return buf[bufPtr++];
	}

	private boolean isTrash(int c) {
		return c < 33 || c > 126;
	}

	private int skip() {
		int b;
		while ((b = readByte()) != -1 && isTrash(b))
			;
		return b;
	}

	String nextToken() {
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while (!isTrash(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	String nextString() {
		int b = readByte();
		StringBuilder sb = new StringBuilder();
		while (!isTrash(b) || b == ' ') {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	double nextDouble() {
		return Double.parseDouble(nextToken());
	}

	char nextChar() {
		return (char) skip();
	}

	int nextInt() {
		int ret = 0;
		int b = skip();
		if (b != '-' && (b < '0' || b > '9')) {
			throw new InputMismatchException();
		}
		boolean neg = false;
		if (b == '-') {
			neg = true;
			b = readByte();
		}
		while (true) {
			if (b >= '0' && b <= '9') {
				ret = ret * 10 + (b - '0');
			} else {
				if (b != -1 && !isTrash(b)) {
					throw new InputMismatchException();
				}
				return neg ? -ret : ret;
			}
			b = readByte();
		}
	}

	long nextLong() {
		long ret = 0;
		int b = skip();
		if (b != '-' && (b < '0' || b > '9')) {
			throw new InputMismatchException();
		}
		boolean neg = false;
		if (b == '-') {
			neg = true;
			b = readByte();
		}
		while (true) {
			if (b >= '0' && b <= '9') {
				ret = ret * 10 + (b - '0');
			} else {
				if (b != -1 && !isTrash(b)) {
					throw new InputMismatchException();
				}
				return neg ? -ret : ret;
			}
			b = readByte();
		}
	}
}


import java.io.*;
import java.math.*;
import java.util.*;
import java.util.stream.*;

public class H {

	boolean solve() {
		int alph = nextInt();
		int n = nextInt();

		int[][] a = new int[n][];
		int tot = 0;
		for (int i = 0; i < n; i++) {
			int k = nextInt();
			int[] che = a[i] = new int[k];
			for (int j = 0; j < k; j++) {
				che[j] = nextInt() - 1;
			}
			tot += k;
		}

		int r = (int) Math.sqrt(tot);
//		int r = 0;

		for (int i = 0, j = n - 1;;) {
			while (i < j && a[i].length <= r) {
				i++;
			}
			while (i < j && a[j].length > r) {
				j--;
			}
			if (i == j) {
				break;
			}

			int[] tmp = a[i];
			a[i] = a[j];
			a[j] = tmp;
		}

		HashMap<Long, Integer> map = new HashMap<>();
		for (int i = 0; i < n; i++) {
			int[] b = a[i];
			if (b.length > r) {
				continue;
			}
			for (int j1 = 0; j1 < b.length; j1++) {
				for (int j2 = j1 + 1; j2 < b.length; j2++) {
					long key = (long) b[j1] * alph + b[j2];
					Integer prev = map.get(key);
					if (prev == null) {
						map.put(key, b[j1 + 1]);
					} else if (prev != b[j1 + 1]) {
						return true;
					}
				}
			}
		}

		int[] id = new int[alph];
		Arrays.fill(id, -2);

		for (int i = 0; i < n; i++) {
			int[] b = a[i];
			if (b.length <= r) {
				break;
			}
			for (int j = 0; j < b.length; j++) {
				id[b[j]] = j;
			}

			for (int j = i + 1; j < n; j++) {
				if (clash(a[j], id)) {
					return true;
				}
			}

			for (int j = 0; j < b.length; j++) {
				id[b[j]] = -2;
			}
		}

		return false;
	}

	boolean clash(int[] a, int[] f) {
		int prev = f[a[0]];
		int curMin = prev == -2 ? Integer.MAX_VALUE : prev;
		for (int i = 1; i < a.length; i++) {
			int now = f[a[i]];
			if (now != prev + 1 && now > curMin) {
				return true;
			}
			if (now != -2) {
				curMin = Math.min(curMin, now);
			}

			prev = now;
		}
		return false;
	}

	void submit() {
		int t = nextInt();
		while (t-- > 0) {
			out.println(solve() ? "Human" : "Robot");
		}
	}

	void test() {

	}

	void stress() {
		for (int tst = 0;; tst++) {
			if (false) {
				throw new AssertionError();
			}
			System.err.println(tst);
		}
	}

	H() throws IOException {
		is = System.in;
		out = new PrintWriter(System.out);
		submit();
		// stress();
		// test();
		out.close();
	}

	static final Random rng = new Random();
	static final int C = 5;

	static int rand(int l, int r) {
		return l + rng.nextInt(r - l + 1);
	}

	public static void main(String[] args) throws IOException {
		new H();
	}

	private InputStream is;
	PrintWriter out;

	private byte[] buf = new byte[1 << 14];
	private int bufSz = 0, bufPtr = 0;

	private int readByte() {
		if (bufSz == -1)
			throw new RuntimeException("Reading past EOF");
		if (bufPtr >= bufSz) {
			bufPtr = 0;
			try {
				bufSz = is.read(buf);
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
			if (bufSz <= 0)
				return -1;
		}
		return buf[bufPtr++];
	}

	private boolean isTrash(int c) {
		return c < 33 || c > 126;
	}

	private int skip() {
		int b;
		while ((b = readByte()) != -1 && isTrash(b))
			;
		return b;
	}

	String nextToken() {
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while (!isTrash(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	String nextString() {
		int b = readByte();
		StringBuilder sb = new StringBuilder();
		while (!isTrash(b) || b == ' ') {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	double nextDouble() {
		return Double.parseDouble(nextToken());
	}

	char nextChar() {
		return (char) skip();
	}

	int nextInt() {
		int ret = 0;
		int b = skip();
		if (b != '-' && (b < '0' || b > '9')) {
			throw new InputMismatchException();
		}
		boolean neg = false;
		if (b == '-') {
			neg = true;
			b = readByte();
		}
		while (true) {
			if (b >= '0' && b <= '9') {
				ret = ret * 10 + (b - '0');
			} else {
				if (b != -1 && !isTrash(b)) {
					throw new InputMismatchException();
				}
				return neg ? -ret : ret;
			}
			b = readByte();
		}
	}

	long nextLong() {
		long ret = 0;
		int b = skip();
		if (b != '-' && (b < '0' || b > '9')) {
			throw new InputMismatchException();
		}
		boolean neg = false;
		if (b == '-') {
			neg = true;
			b = readByte();
		}
		while (true) {
			if (b >= '0' && b <= '9') {
				ret = ret * 10 + (b - '0');
			} else {
				if (b != -1 && !isTrash(b)) {
					throw new InputMismatchException();
				}
				return neg ? -ret : ret;
			}
			b = readByte();
		}
	}
}