#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

const int N=105*2;

struct Search_t{
	int n;
	int G[N][N];
	int w[N][N];
	int op[N];
	int v[N];
	int used[N];
	int tmp_u[N];
	int ans,now;

	bool Can_choose(int k){
		for (int i=1;i<=n;i++){
			if (v[i] && !used[i] && G[k][i]) return false;
			if (v[i] && used[i] && G[i][op[k]]) return false;
		}
		return true;
	}

	int greedy(int k){
		int ret=0;
		for (int i=1;i<=n;i++) tmp_u[i]=used[i];
        for (int i=k;i<=n;i++)
            if (!v[i]){
                bool check=true;
                for (int j=1;j<=n;j++)
                    if (v[j] && !used[j] && G[i][j]) { check=false; break; }
                if (!check) continue;
                ret+=w[i][i];
                for (int j=1;j<=n;j++)
                    if (tmp_u[j])
                        ret+=w[i][j];
                tmp_u[i]=1;
            }
		return ret;
	}

	void Choose(int k){
		v[k]=1;
		v[op[k]]=1;
		used[k]=1;
		now+=w[k][k];
		for (int i=1;i<=n;i++)
			if (v[i] && used[i] && i!=k) now+=w[i][k];
	}

	void Remove(int k){
		v[k]=0;
		v[op[k]]=0;
		used[k]=0;
		now-=w[k][k];
		for (int i=1;i<=n;i++)
			if (v[i] && used[i] && i!=k) now-=w[i][k];
	}

	void dfs(int dep){
		if (dep>n){
			if (now>ans) ans=now;
			return;
		}
		if (now+greedy(dep)<=ans)
            return;
		if (v[dep]) dfs(dep+1);
		else{
			bool s1=Can_choose(dep);
			bool s2=Can_choose(op[dep]);
			if (s1 && s2){
				Choose(dep);
				int w1=now+greedy(dep+1);
				Remove(dep);
				
				Choose(op[dep]);
				int w2=now+greedy(dep+1);
				Remove(op[dep]);
				
				if (w1>w2){
					Choose(dep);
					dfs(dep+1);
					Remove(dep);
					
					Choose(op[dep]);
					dfs(dep+1);
					Remove(op[dep]);
				}
				else{
					Choose(op[dep]);
					dfs(dep+1);
					Remove(op[dep]);
					
					Choose(dep);
					dfs(dep+1);
					Remove(dep);
				}
			}
			else
			if (s1){
				Choose(dep);
				dfs(dep+1);
				Remove(dep);
			}
			else
			if (s2){
				Choose(op[dep]);
				dfs(dep+1);
				Remove(op[dep]);
			}
		}
	}

	void gao(){
		memset(v,0,sizeof(v));
		memset(used,0,sizeof(used));
		now=0;
		ans=0;
		dfs(1);
		printf("%d\n",ans);
	}
}Search;
#define op(x) ((x)>n?(x)-n:(x)+n)
int m,n,Cn;
int mat[N][N];
int G[N][N];
int Only[N][N];
int Color[N];
int P;

void solve(){
	memset(G,0,sizeof(G));
	for (int i=1;i<=2*n;i++)
		for (int j=1;j<=2*n;j++)
			if (mat[i][j] && Color[i]!=Color[j])
				G[Color[i]][Color[j]]=1;
	memset(Only,0,sizeof(Only));
	for (int i=1;i<=n;i++){
		Only[Color[i]][Color[op(i)]]=1;
		Only[Color[op(i)]][Color[i]]=1;
	}
	memcpy(Search.G,G,sizeof(G));
	memset(Search.w,0,sizeof(Search.w));
	for (int i=1;i<=Cn;i++)
		for (int j=1;j<=Cn;j++)
			if (Only[i][j]){
				Search.op[i]=j;
				Search.op[j]=i;
			}
	Search.n=Cn;
	for (int i=0;i<P;i++){
		int a,b,x,y,w;
		scanf("%d%d%d%d%d",&a,&x,&b,&y,&w);
		if (x==0) a+=n;
		if (y==0) b+=n;
		Search.w[Color[a]][Color[b]]+=w;
		if (Color[a]!=Color[b]) Search.w[Color[b]][Color[a]]+=w;
	}
	Search.gao();
}

int main(){
	while (scanf("%d%d%d",&n,&m,&P)!=EOF){
		memset(mat,0,sizeof(mat));
		for (int i=0;i<m;i++){
			int x,y,c;
			char oper[10];
			char Tmp[10];
			scanf("%d %s %d %s %d",&x,oper,&y,Tmp,&c);
			switch (oper[0]){
				case 'x':
					if (c){
						mat[x][op(y)]=1;
						mat[y][op(x)]=1;
						mat[op(x)][y]=1;
						mat[op(y)][x]=1;
					}
					else{
						mat[x][y]=1;
						mat[y][x]=1;
						mat[op(x)][op(y)]=1;
						mat[op(y)][op(x)]=1;
					}
					break;
				case 'o':
					if (c){
						mat[op(x)][y]=1;
						mat[op(y)][x]=1;
					}
					else{
						mat[x][op(x)]=1;
						mat[y][op(y)]=1;
					}
					break;
				case 'a':
					if (c){
						mat[op(x)][x]=1;
						mat[op(y)][y]=1;
					}
					else{
						mat[x][op(y)]=1;
						mat[y][op(x)]=1;
					}
					break;
			}
		}
		for (int k=1;k<=2*n;k++)
			for (int i=1;i<=2*n;i++)
				for (int j=1;j<=2*n;j++)
					mat[i][j]|=mat[i][k]&mat[k][j];
		Cn=0;
		memset(Color,0,sizeof(Color));
		for (int i=1;i<=2*n;i++)
			if (!Color[i]){
				Color[i]=++Cn;
				for (int j=1;j<=2*n;j++)
					if (mat[i][j] && mat[j][i])
						Color[j]=Cn;
			}
		bool check=true;
		for (int i=1;i<=n;i++)
			if (Color[i]==Color[op(i)]) check=false;
		if (!check) puts("No solution");
			   else solve();
	}
	return 0;
}
