#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

struct abcd {
  int a;
  int b;
  int c;
  long long int d;
};

void swap(struct abcd *left, struct abcd *right) {
  struct abcd tmp;
  tmp.a = left->a;
  tmp.b = left->b;
  tmp.c = left->c;
  tmp.d = left->d;
  left->a = right->a;
  left->b = right->b;
  left->c = right->c;
  left->d = right->d;
  right->a = tmp.a;
  right->b = tmp.b;
  right->c = tmp.c;
  right->d = tmp.d;
}

void sort(struct abcd *array, int left, int right) {
  if (left >= right) return;

  long long int pivot = array[(right + left) / 2].d;
  int p_l = left, p_r = right;
  while (p_l < p_r) {
    while (array[p_l].d < pivot) p_l++;
    while (array[p_r].d > pivot) p_r--;
    if (p_l < p_r) {
      swap(&array[p_l], &array[p_r]);
    }
  }

  // swap(&array[p_r], &array[left]);
  
  sort(array, left, p_r);
  sort(array, p_r + 1, right);
}

int main(void) {
  int n, m, q;
  scanf("%d %d %d", &n, &m, &q);
  struct abcd abcd[q];
  for (int i = 0; i < q; i++) {
    scanf(" %d %d %d %lld", &abcd[i].a, &abcd[i].b, &abcd[i].c, &abcd[i].d);
  }

  // printf("\n");
  sort(abcd, 0, q);

  /*
  for (int i = 0; i < q; i++) {
    printf("%d %d %d %lld\n", abcd[i].a, abcd[i].b, abcd[i].c, abcd[i].d);
  }
  */

  int num[n];
  int count[n];
  int query[n][3];
  for (int i = 0; i < n; i++) {
    num[i] = 0;
    count[i] = 0;
  }
  long long int score = 0;
  int query_count = 0;
  for (int i = n - 1; i >= 0; i--) {
    struct abcd tmp = abcd[i];
    if (count[tmp.b] < 2) {
      count[tmp.b]++;
      count[tmp.a]++;
      query[query_count][0] = tmp.a;
      query[query_count][1] = tmp.b;
      query[query_count][2] = tmp.c;
      query_count++;
      score += tmp.d;
    } else {
      for (int j = 0; j < query_count; j++) {
        if (query[j][0] == tmp.a && query[j][1] == tmp.b && query[j][2] != tmp.c) break;
        else {
          count[tmp.b]++;
          count[tmp.a]++;
          query[query_count][0] = tmp.a;
          query[query_count][1] = tmp.b;
          query[query_count][2] = tmp.c;
          query_count++; 
          score += tmp.d;
        }
      }
    }

    printf("%lld\n", score);
  }

  return 0;
}
