from collections import Counter,defaultdict,deque

from heapq import heappop,heappush,heapify

from bisect import bisect_left,bisect_right 

import sys,math,itertools,fractions,pprint

sys.setrecursionlimit(10**8)

mod = 10**9+7

INF = float('inf')

def inp(): return int(sys.stdin.readline())

def inpl(): return list(map(int, sys.stdin.readline().split()))



def cal(x):

    rr = 0

    for i in range(Q):

        a,b,c,d = query[i]

        if x[b] - x[a] == c:

            rr += d

    return rr



n,m,Q = inpl()

q = deque()

q.append([1])

query = []

for _ in range(Q):

    query.append(inpl())

res = 0

while q:

    now = q.popleft()

    if len(now) == n+1:

        res = max(res, cal(now))

        continue

    for i in range(now[-1],m+1):

        tmp = now + [i]

        q.append(tmp)

print(res)
from collections import Counter,defaultdict,deque

from heapq import heappop,heappush,heapify

import sys,bisect,math,itertools,fractions,pprint

sys.setrecursionlimit(10**8)

mod = 10**9+7

INF = float('inf')

def inp(): return int(sys.stdin.readline())

def inpl(): return list(map(int, sys.stdin.readline().split()))





n,m,q = inpl()

abc = [inpl() for _ in range(q)]

q = deque()

q.append([1])

res = 0

while q:

    now = q.popleft()

    if len(now) == n+1:

        # print(now)

        ans = 0

        for i,x in enumerate(abc):

            a,b,c,d = x

            if now[b] - now[a] == c:

                ans += d

        res = max(ans, res)

        continue

    for i in range(now[-1], m+1):

        q.append(now + [i])

print(res)

from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heapify
from bisect import bisect_left, bisect_right
import sys, math, itertools, fractions, pprint

sys.setrecursionlimit(10**8)
mod = 10**9 + 7
INF = float("inf")


def inp():
    return int(sys.stdin.readline())


def inpl():
    return list(map(int, sys.stdin.readline().split()))


def cal(x):
    rr = 0
    for i in range(Q):
        a, b, c, d = query[i]
        if x[b] - x[a] == c:
            rr += d
    return rr


n, m, Q = inpl()
q = deque()
q.append([1])
query = []
for _ in range(Q):
    query.append(inpl())
res = 0
while q:
    now = q.popleft()
    if len(now) == n + 1:
        res = max(res, cal(now))
        continue
    for i in range(now[-1], m + 1):
        tmp = now + [i]
        q.append(tmp)
print(res)

from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heapify
import sys, bisect, math, itertools, fractions, pprint

sys.setrecursionlimit(10**8)
mod = 10**9 + 7
INF = float("inf")


def inp():
    return int(sys.stdin.readline())


def inpl():
    return list(map(int, sys.stdin.readline().split()))


n, m, q = inpl()
abc = [inpl() for _ in range(q)]
q = deque()
q.append([1])
res = 0
while q:
    now = q.popleft()
    if len(now) == n + 1:
        # print(now)
        ans = 0
        for i, x in enumerate(abc):
            a, b, c, d = x
            if now[b] - now[a] == c:
                ans += d
        res = max(ans, res)
        continue
    for i in range(now[-1], m + 1):
        q.append(now + [i])
print(res)

-from bisect import bisect_left, bisect_right -import sys, math, itertools, fractions, pprint +import sys, bisect, math, itertools, fractions, pprint -def cal(x): -    rr = 0 -    for i in range(Q): -        a, b, c, d = query[i] -        if x[b] - x[a] == c: -            rr += d -    return rr - - -n, m, Q = inpl() +n, m, q = inpl() +abc = [inpl() for _ in range(q)] -query = [] -for _ in range(Q): -    query.append(inpl()) -        res = max(res, cal(now)) +        # print(now) +        ans = 0 +        for i, x in enumerate(abc): +            a, b, c, d = x +            if now[b] - now[a] == c: +                ans += d +        res = max(ans, res) -        tmp = now + [i] -        q.append(tmp) +        q.append(now + [i])