const Main = input => {
    const inp = input.split("\n");
    const [n, m, q] = inp[0].split(" ");
    const arr = [];
    for(let i = 1; i < inp.length; i++) {
        const a = inp[i].split(" ");
        arr[i - 1] = [];
        for(let j = 0; j < 4; j++) {
            arr[i - 1][j] = parseInt(a[j], 10);
        }
    }

    const A = [1, 3, 4];
    let result = 0;
    for(let i = 0; i < arr.length; i++) {
        if(A[arr[i][1]] - A[arr[i][0]] === arr[i][2]) result += arr[i][3];
    }
    console.log(result);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));