#include<stdio.h>

int dfs(int x, int f, int a[100][100], int b[100], int p[100]);
int G[100][100],visited[100]={0}, n, p[100]={0};

int main()
{
    int i,j,h,m,b,z,suma,k;
    suma=0;
    FILE *ptrIn=fopen("input.txt", "r");
    FILE *ptrOu=fopen("output.txt", "w");
    fscanf(ptrIn,"%i",&n);
    for(m=0;m<n;m++){
        fscanf(ptrIn,"%i",&b);
        for(i=0;i<b-1;i++)
        {
            fscanf(ptrIn,"%i%i", &h, &j);
            h--;
            j--;
            G[h][p[h++]]=j;
            G[j][p[j++]]=h;
        }
        for(i=0;i<n;i++){
            k=dfs(j,0,G,visited,p);
            if(k>z)
                z=k;
        }
        suma+=z;
    }
     fprintf(ptrOu,"%i",suma);
     return 0;
}

int dfs(int x, int f, int a[100][100], int b[100], int p[100])
{
     int m1 = 0, m2 = 0, i;

     b[x] = 1;

     for (i = 0; i < p[x]; i++) {
      if (b[a[x][i]] == 0) {
           int m = dfs(a[x][i], 1, a, b, p) + 1;

           if (m > m1) {
            m2 = m1;
            m1 = m;
           } else if (m > m2) {
            m2 = m;
           }
      }
     }

     if (f == 0) {
      return m1 + m2;
     } else {
      return m1;
     }
}


#include<stdio.h>

int dfs(int x, int f, int a[100][100], int b[100], int p[100]);
int G[100][100],visited[100]={0}, n, p[100]={0};

int main()
{
    int i,j,h,m,b,z,suma,k=0;
    FILE *ptrIn=fopen("input.txt", "r");
    FILE *ptrOu=fopen("output.txt", "w");
    fscanf(ptrIn,"%i",&n);
    for(m=0;m<n;m++){
            z=0;
        fscanf(ptrIn,"%i",&b);
        for(i=0;i<b-1;i++)
        {
            fscanf(ptrIn,"%i%i", &h, &j);
            h--;
            j--;
            G[h][p[h++]]=j;
            G[j][p[j++]]=h;
        }
        for(i=0;i<n;i++){
            k=dfs(j,0,G,visited,p);
            if(k>b)
                z=k;
        }
        suma+=z;
    }
     fprintf(ptrOu,"%i",k);
     return 0;
}

int dfs(int x, int f, int a[100][100], int b[100], int p[100])
{
     int m1 = 0, m2 = 0, i;

     b[x] = 1;

     for (i = 0; i < p[x]; i++) {
      if (b[a[x][i]] == 0) {
           int m = dfs(a[x][i], 1, a, b, p) + 1;

           if (m > m1) {
            m2 = m1;
            m1 = m;
           } else if (m > m2) {
            m2 = m;
           }
      }
     }

     if (f == 0) {
      return m1 + m2;
     } else {
      return m1;
     }
}


#include<stdio.h>

int dfs(int x, int f, int a[100][100], int b[100], int p[100]);
int n;

int main()
{
    int i,j,h,m,b,z,suma,k;
    suma=0;
    z=0;
    FILE *ptrIn=fopen("input.txt", "r");
    FILE *ptrOu=fopen("output.txt", "w");
    fscanf(ptrIn,"%i",&n);
    for(m=0;m<n;m++){
        int G[100][100];
        int p[100]={0};
        fscanf(ptrIn,"%i",&b);
        for(i=0;i<b-1;i++)
        {
            fscanf(ptrIn,"%i%i", &h, &j);
            h--;
            j--;
            G[h][p[h]++]=j;
            G[j][p[j]++]=h;
        }
        for(i=0;i<n;i++){
            int visited[100] = {0};
            k=dfs(j,0,G,visited,p);
            if(k>z)
                z=k;
        }
        suma+=z;
    }
     fprintf(ptrOu,"%i\n",suma);
     fclose(ptrOu);
     fclose(ptrIn);
}

int dfs(int x, int f, int a[100][100], int b[100], int p[100])
{
     int m1 = 0, m2 = 0, i;

     b[x] = 1;

     for (i = 0; i < p[x]; i++) {
      if (b[a[x][i]] == 0) {
           int m = dfs(a[x][i], 1, a, b, p) + 1;

           if (m > m1) {
            m2 = m1;
            m1 = m;
           } else if (m > m2) {
            m2 = m;
           }
      }
     }

     if (f == 0) {
      return m1 + m2;
     } else {
      return m1;
     }
}


#include<stdio.h>

int DFS(int);
int G[100][100],visited[100]={0}, n,k=0;

void main()
{
    int i,j,h,m,b;
    FILE *ptrIn=fopen("input.txt", "r");
    FILE *ptrOu=fopen("output.txt", "w");
    while(fscanf(ptrIn,"%i",&n) != EOF){
    while(n--){
    scanf("%i",&b);
        for(i=0;i<b-1;i++)
        {
            fscanf(ptrIn,"%i%i", &h, &j);
            G[h][j]=1;
        }
    }
    }
     fprintf(ptrOu,"%i",k);
}

int DFS(int i)
{
    int j;
    k++;
    visited[i]=1;
    for(j=0;j<n;j++)
       if(!visited[j]&&G[i][j]==1){
            DFS(j);
       }
    return k;
}


#include<stdio.h>

int dfs(int x, int f, int a[100][100], int b[100], int p[100]);
int n;

int main()
{
    int i,j,h,m,b,z,suma,k;
    suma=0;
    FILE *ptrIn=fopen("input.txt", "r");
    FILE *ptrOu=fopen("output.txt", "w");
    fscanf(ptrIn,"%i",&n);
    for(m=0;m<n;m++){
        int G[100][100];
        int p[100]={0};
        int z=0;
        fscanf(ptrIn,"%i",&b);
        for(i=0;i<b-1;i++)
        {
            fscanf(ptrIn,"%i%i", &h, &j);
            h--;
            j--;
            G[h][p[h]++]=j;
            G[j][p[j]++]=h;
        }
        for(i=0;i<n;i++){
            int visited[100] = {0};
            k=dfs(j,0,G,visited,p);
            if(k>z)
                z=k;
        }
        suma+=z;
    }
     fprintf(ptrOu,"%i\n",suma);
     fclose(ptrOu);
     fclose(ptrIn);
}

int dfs(int x, int f, int a[100][100], int b[100], int p[100])
{
     int m1 = 0, m2 = 0, i;

     b[x] = 1;

     for (i = 0; i < p[x]; i++) {
      if (b[a[x][i]] == 0) {
           int m = dfs(a[x][i], 1, a, b, p) + 1;

           if (m > m1) {
            m2 = m1;
            m1 = m;
           } else if (m > m2) {
            m2 = m;
           }
      }
     }

     if (f == 0) {
      return m1 + m2;
     } else {
      return m1;
     }
}


#include<stdio.h>

int dfs(int x, int f, int a[100][100], int b[100], int p[100]);
int G[100][100],visited[100]={0}, n, p[100]={0};

int main()
{
    int i,j,h,m,b,z,suma,k=0;
    FILE *ptrIn=fopen("input.txt", "r");
    FILE *ptrOu=fopen("output.txt", "w");
    fscanf(ptrIn,"%i",&n);
     z=0;
    for(m=0;m<n;m++){
        fscanf(ptrIn,"%i",&b);
        for(i=0;i<b-1;i++)
        {
            fscanf(ptrIn,"%i%i", &h, &j);
            h--;
            j--;
            G[h][p[h++]]=j;
            G[j][p[j++]]=h;
        }
        for(i=0;i<n;i++){
            k=dfs(j,0,G,visited,p);
            if(k>b)
                z=k;
        }
        suma+=z;
    }
     fprintf(ptrOu,"%i",k);
     return 0;
}

int dfs(int x, int f, int a[100][100], int b[100], int p[100])
{
     int m1 = 0, m2 = 0, i;

     b[x] = 1;

     for (i = 0; i < p[x]; i++) {
      if (b[a[x][i]] == 0) {
           int m = dfs(a[x][i], 1, a, b, p) + 1;

           if (m > m1) {
            m2 = m1;
            m1 = m;
           } else if (m > m2) {
            m2 = m;
           }
      }
     }

     if (f == 0) {
      return m1 + m2;
     } else {
      return m1;
     }
}


#include<stdio.h>

int dfs(int x, int f, int a[100][100], int b[100], int p[100]);
int G[100][100],visited[100]={0}, n, p[100]={0};

int main()
{
    int i,j,h,m,b,z,suma,k=0;
    suma=0;
    FILE *ptrIn=fopen("input.txt", "r");
    FILE *ptrOu=fopen("output.txt", "w");
    fscanf(ptrIn,"%i",&n);
     z=0;
    for(m=0;m<n;m++){
        fscanf(ptrIn,"%i",&b);
        for(i=0;i<b-1;i++)
        {
            fscanf(ptrIn,"%i%i", &h, &j);
            h--;
            j--;
            G[h][p[h++]]=j;
            G[j][p[j++]]=h;
        }
        for(i=0;i<n;i++){
            k=dfs(j,0,G,visited,p);
            if(k>z)
                z=k;
        }
        suma+=z;
    }
     fprintf(ptrOu,"%i",suma);
     return 0;
}

int dfs(int x, int f, int a[100][100], int b[100], int p[100])
{
     int m1 = 0, m2 = 0, i;

     b[x] = 1;

     for (i = 0; i < p[x]; i++) {
      if (b[a[x][i]] == 0) {
           int m = dfs(a[x][i], 1, a, b, p) + 1;

           if (m > m1) {
            m2 = m1;
            m1 = m;
           } else if (m > m2) {
            m2 = m;
           }
      }
     }

     if (f == 0) {
      return m1 + m2;
     } else {
      return m1;
     }
}


#include<stdio.h>

int dfs(int x, int f, int a[100][100], int b[100], int p[100]);
int G[100][100],visited[100]={0}, n, p[100]={0},k;

int main()
{
    int i,j,h,m,b,z,suma,k;
    suma=0;
    z=0;
    FILE *ptrIn=fopen("input.txt", "r");
    FILE *ptrOu=fopen("output.txt", "w");
    fscanf(ptrIn,"%i",&n);
    for(m=0;m<n;m++){
        fscanf(ptrIn,"%i",&b);
        for(i=0;i<b-1;i++)
        {
            fscanf(ptrIn,"%i%i", &h, &j);
            h--;
            j--;
            G[h][p[h]++]=j;
            G[j][p[j]++]=h;
        }
        for(i=0;i<n;i++){
            k=dfs(j,0,G,visited,p);
            if(k>z)
                z=k;
        }
        suma+=z;
    }
     fprintf(ptrOu,"%i\n",suma);
     fclose(ptrOu);
     fclose(ptrIn);
}

int dfs(int x, int f, int a[100][100], int b[100], int p[100])
{
     int m1 = 0, m2 = 0, i;

     b[x] = 1;

     for (i = 0; i < p[x]; i++) {
      if (b[a[x][i]] == 0) {
           int m = dfs(a[x][i], 1, a, b, p) + 1;

           if (m > m1) {
            m2 = m1;
            m1 = m;
           } else if (m > m2) {
            m2 = m;
           }
      }
     }

     if (f == 0) {
      return m1 + m2;
     } else {
      return m1;
     }
}


#include<stdio.h>

int dfs(int x, int f, int a[100][100], int b[100], int p[100]);
int G[100][100],visited[100]={0}, n, p[100]={0};

int main()
{
    int i,j,h,m,b,z,suma,k=0;
    FILE *ptrIn=fopen("input.txt", "r");
    FILE *ptrOu=fopen("output.txt", "w");
    fscanf(ptrIn,"%i",&n);
     z=0;
    for(m=0;m<n;m++){
        fscanf(ptrIn,"%i",&b);
        for(i=0;i<b-1;i++)
        {
            fscanf(ptrIn,"%i%i", &h, &j);
            h--;
            j--;
            G[h][p[h++]]=j;
            G[j][p[j++]]=h;
        }
        for(i=0;i<n;i++){
            k=dfs(j,0,G,visited,p);
            if(k>z)
                z=k;
        }
        suma+=z;
    }
     fprintf(ptrOu,"%i",suma);
     return 0;
}

int dfs(int x, int f, int a[100][100], int b[100], int p[100])
{
     int m1 = 0, m2 = 0, i;

     b[x] = 1;

     for (i = 0; i < p[x]; i++) {
      if (b[a[x][i]] == 0) {
           int m = dfs(a[x][i], 1, a, b, p) + 1;

           if (m > m1) {
            m2 = m1;
            m1 = m;
           } else if (m > m2) {
            m2 = m;
           }
      }
     }

     if (f == 0) {
      return m1 + m2;
     } else {
      return m1;
     }
}


#include<stdio.h>

int dfs(int x, int f, int a[100][100], int b[100], int p[100]);
int G[100][100],visited[100]={0}, n, p[100]={0},k;

int main()
{
    int i,j,h,m,b,z,suma,k;
    suma=0;
    z=0;
    FILE *ptrIn=fopen("input.txt", "r");
    FILE *ptrOu=fopen("output.txt", "w");
    fscanf(ptrIn,"%i",&n);
    for(m=0;m<n;m++){
        fscanf(ptrIn,"%i",&b);
        for(i=0;i<b-1;i++)
        {
            fscanf(ptrIn,"%i%i", &h, &j);
            h--;
            j--;
            G[h][p[h]++]=j;
            G[j][p[j]++]=h;
        }
        for(i=0;i<n;i++){
            k=dfs(j,0,G,visited,p);
            if(k>z)
                z=k;
        }
        suma+=z;
    }
     printf(ptrOu,"%i",suma);
     return 0;
}

int dfs(int x, int f, int a[100][100], int b[100], int p[100])
{
     int m1 = 0, m2 = 0, i;

     b[x] = 1;

     for (i = 0; i < p[x]; i++) {
      if (b[a[x][i]] == 0) {
           int m = dfs(a[x][i], 1, a, b, p) + 1;

           if (m > m1) {
            m2 = m1;
            m1 = m;
           } else if (m > m2) {
            m2 = m;
           }
      }
     }

     if (f == 0) {
      return m1 + m2;
     } else {
      return m1;
     }
}


#include<stdio.h>

int graph[200][200],n,k,l,i,j,a,b,t,m,s,h[200];

void f(int j,int p)
{
    int i;
    if(h[j])
    return;
    h[j]=1;
    if(p>m)
    m=p;
    for(i=1;i<=k;i++)
    {
        if(graph[j][i])
            f(i,p+1);
    }
    h[j]=0;
}

int main()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        for(j=0;j<110;j++)
            for(l=0;l<110;l++)graph[j][l]=0;
        scanf("%d",&k);
        m=0;
        for(j=1;j<k;j++)
        {
            scanf("%d%d",&a,&b);
            graph[a][b]=graph[b][a]=1;
        }
        for(j=1;j<=k;j++)
            f(j,0);
        t+=m;
    }
    printf("%d",t);
}


#include<stdio.h>

int grafo[200][200];
int n,k,l,i,j,a,b,t,m,s;
int v[200];

void f(int j,int p)
{
    int i;
    if(v[j])
    return;
    v[j]=1;
    if(p>m)
    m=p;
    for(i=1;i<=k;i++)
    {
        if(grafo[j][i])
            f(i,p+1);
    }
    v[j]=0;
}

int main()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        for(j=0;j<110;j++)
            for(l=0;l<110;l++)
                grafo[j][l]=0;
        scanf("%d",&k);
        m=0;
        for(j=1;j<k;j++)
        {
            scanf("%d%d",&a,&b);
            grafo[a][b]=grafo[b][a]=1;
        }
        for(j=1;j<=k;j++)
            f(j,0);
        t+=m;
    }
    printf("%d",t);
}


#include<stdio.h>
#include<string.h>
int max;
int result;
int map [110][110];
void dps(int w,int v,int lvl);
int main(){
    int n,k,i,j,l,r,z;
    FILE *in=fopen("input.txt","r");
    FILE *out=fopen("output.txt","w");
    fscanf(in,"%d",&n);
    for(l=0;l<n;l++){
        fscanf(in,"%d",&k);
        for(r=1;r<k;r++){
            fscanf(in,"%d %d",&i,&j);
            map[i][++map[i][0]]=j;
            map[j][++map[j][0]]=i;
        }
        max=0;
        for(r=1;r<=k;r++){
            dps(r,0,0);
        }
        memset(map,0,48400);
        result+=max;
    }
    fprintf(out,"%d",result);
    fclose(in);
    fclose(out);
    return 0;
}
void dps(int w,int v,int lvl){
    int i,j,l;
    if(map[w][0]==1 && v){
        max=max>lvl? (max) : (lvl);
    }else{
        for(l=1;l<=map[w][0];l++){
            if(map[w][l]!=v){
                dps(map[w][l],w,lvl+1);
            }
        }
    }
}


#include<stdio.h>
#include<string.h>
int max;
int result;
int visited[110];
int map [110][110];
void dps(int w,int lvl);
int main(){
    int n,k,i,j,l,r,z;
    FILE *in=fopen("input.txt","r");
    FILE *out=fopen("output.txt","w");
    fscanf(in,"%d",&n);
    for(l=0;l<n;l++){
        fscanf(in,"%d",&k);
        for(r=1;r<k;r++){
            fscanf(in,"%d %d",&i,&j);
            map[i][++map[i][0]]=j;
            map[j][++map[j][0]]=i;
        }
        for(r=1;r<=k;r++){
            dps(r,0);
        }
        memset(map,0,48400);
        result+=max;
    }
    fprintf(out,"%d",result);
    fclose(in);
    fclose(out);
    return 0;
}
void dps(int w,int lvl){
    int i,j,l,r;
    visited[w]=1;
    max=max>lvl?(max):(lvl);
    for(l=1;l<=map[w][0];l++){
        if(!visited[r=map[w][l]]){
            dps(r,lvl+1);
        }
    }
    visited[w]=0;
}


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

//funtions
int buscar(int x, int f, int a[100][100], int b[100], int p[100]);

int main()
{
     int n, k, sum = 0, i, j;
     FILE *fila1, *fila2;

     fila1 = fopen("input.txt", "r");
     fila2 = fopen("output.txt", "w");

     fscanf(fila1, "%d", &n);

     for (i = 0; i < n; i++) {
      int a[100][100];
      int p[100] = {0};
      int m = 0;

      fscanf(fila1, "%d", &k);

      for (j = 0; j < k - 1; j++) {
           int x, y;

           fscanf(fila1, "%d %d", &x, &y);

           x--; y--;

           a[x][p[x]++] = y;
           a[y][p[y]++] = x;
      }

      for (j = 0; j < k; j++) {
           int b[100] = {0};
           int c = buscar(j, 0, a, b, p);

           if (c > m) m = c;
      }

      sum += m;
     }

     fprintf(fila2, "%d\n", sum);

     fclose(fila1);
     fclose(fila2);

     return 0;
}
int buscar(int x, int f, int a[100][100], int b[100], int p[100])
{
     int m1 = 0, m2 = 0, i;

     b[x] = 1;

     for (i = 0; i < p[x]; i++) {
      if (b[a[x][i]] == 0) {
           int m = buscar(a[x][i], 1, a, b, p) + 1;

           if (m > m1) {
            m2 = m1;
            m1 = m;
           } else if (m > m2) {
            m2 = m;
           }
      }
     }

     if (f == 0) {
      return m1 + m2;
     } else {
      return m1;
     }
}


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

typedef struct nodoDirectorio{
    int vertice;
    struct nodoAdyacente *lista;
    struct nodoDirectorio *enlace;
    int distancia;

} NodoGrafo;

typedef NodoGrafo* TipoDato;

typedef struct nodo
{
    TipoDato elemento;
    struct nodo *ste;
} Nodo;

void crearPila(Nodo **pila);
void insertar(Nodo **pila,TipoDato elemento);
TipoDato quitar(Nodo **pila);
int pilaVacia(Nodo *pila);

typedef struct nodoAdyacente
{
    struct nodoDirectorio *destino;
    struct nodoAdyacente *enlace;
} NodoLista;

void nuevoVertice(NodoGrafo **grafo, int vertice);
void arista(NodoGrafo *grafo, int org, int dst);
NodoGrafo* direccion(NodoGrafo *grafo,int vert);
void recorreProfundidad(NodoGrafo *grafo,int n, int v, int m[]);

int total = 0;
int longitud = 0;

int main()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    int nro;
    scanf("%d",&nro);
    NodoGrafo *vec[nro];
    int i,x,y,mayor = 0, k,total=0;
    for( k = 0; k < nro; k++)
    {
        vec[k] = NULL;

        int n;
        scanf("%d",&n);

        for( i = 1; i <= n; i++)
        {
            nuevoVertice(&vec[k],i);
        }
        for( i = 1; i <=n-1; i++)
        {
            scanf("%d%d",&x,&y);

            arista(vec[k],x,y);
            arista(vec[k],y,x);

        }
           int m[n];
            mayor = 0;
           longitud = 0;
        for( i = 1; i <= n; i++)
        {
            recorreProfundidad(vec[k],n,i,m);
            if(longitud > mayor){mayor = longitud;}
        }
        total = total + mayor;
    }
            printf("%d",total);

    return 0;

}
void nuevoVertice(NodoGrafo **grafo, int vertice)
{
    NodoGrafo *nuevo;
    nuevo = (NodoGrafo*)malloc(sizeof(NodoGrafo));
    nuevo -> vertice = vertice;
    nuevo -> lista = NULL;
    nuevo -> enlace = *grafo;
    *grafo = nuevo;
}
void arista(NodoGrafo *grafo, int org, int dst)
{
    NodoGrafo *v1,*v2;
    NodoLista *ady;

    v1 = direccion(grafo,org);
    v2 = direccion(grafo,dst);

    if( v1 && v2 )
    {
        ady = (NodoLista*)malloc(sizeof(NodoLista));
        ady -> destino = v2;
        ady -> enlace = v1 -> lista;
        v1 -> lista = ady;
    }
}

NodoGrafo* direccion(NodoGrafo *grafo,int vert)
{
    NodoGrafo *aux;

    aux = grafo;

    while( aux -> vertice != vert && aux != NULL )
    {
        aux = aux -> enlace;
    }
    return aux;

}

void crearPila(Nodo **pila)
{
    *pila = NULL;
}

int pilaVacia(Nodo *pila)
{
    return pila == NULL;
}

void insertar(Nodo **pila,TipoDato elemento)
{
    Nodo *nuevo;

    nuevo = (Nodo*)malloc(sizeof(Nodo));
    nuevo -> elemento = elemento;
    nuevo -> ste = *pila;
    (*pila) = nuevo;
}

TipoDato quitar(Nodo **pila)
{
    TipoDato tem;
    Nodo *q;

    if(pilaVacia(*pila))
    {
        exit(1);
    }

    tem = (*pila) -> elemento;
    q = *pila;
    (*pila) = (*pila) -> ste;
    free(q);

    return tem;
}

void recorreProfundidad(NodoGrafo *grafo,int n, int v, int m[])
{
    NodoGrafo *v1,*v2,*w;
    NodoLista *ady;
    Nodo *pila;

    crearPila(&pila);
    int i;
    int tiempos[n];
    for( i = 0; i < n; i++)
    {
        m[i] = -1;
        tiempos[i] = 0;
    }
    m[v-1] = 0;

    v1 = direccion(grafo,v);
    insertar(&pila,v1);
    total = 0;
    v1 -> distancia = 0;
    while(!pilaVacia(pila))
    {

        w = quitar(&pila);
        ady = w -> lista;
        while(ady != NULL)
        {

            int k;
            k = ady -> destino -> vertice - 1;
            if(m[k] == -1)
            {
                insertar(&pila,ady->destino);
                m[k] = 1;
                ady -> destino -> distancia = w -> distancia + 1;
                if(ady -> destino -> distancia > longitud)
                    longitud = ady -> destino -> distancia;

            }

            ady = ady -> enlace;
        }

    }

}


#include <stdlib.h>
#include <stdio.h>
#include <memory.h>
#define N 110

int raiz[N],nodo[N*2],siguiente[N*2];
int longitud,e;
void inicializar();
void agregar_nodo(int ,int );
int mayor(int ,int );
int bus_profundidad(int ,int );

int main(){
    FILE *ptrIn=fopen("input.txt", "r");
    FILE *ptrOu=fopen("output.txt", "w");
    int n,m,v,a;
    while(fscanf(ptrIn,"%d",&n) != EOF){
        int res;
        res = 0;
        while(n--){
            fscanf(ptrIn,"%d",&m);
            inicializar();
            longitud;
            longitud = 0;
            int i;
            for(i = 0;i < m-1;i++){
                fscanf(ptrIn,"%d%d",&v,&a);
                agregar_nodo(v,a);
                agregar_nodo(a,v);
            }
            bus_profundidad(1,-1);
            res += longitud;
        }
        fprintf(ptrOu,"%d",res);
    }
    return 0;
}

void inicializar(){
    e = 0;
    memset(raiz,-1,sizeof(raiz));
}

void agregar_nodo(int a,int b){
    nodo[e] = b;
    siguiente[e] = raiz[a];
    raiz[a] = e++;
}

int bus_profundidad(int u,int g){
    int r,max,i;
    r = 0;
    for(i = raiz[u];i != -1;i = siguiente[i]){
        if(nodo[i] == g){
            continue;
        }
        max = bus_profundidad(nodo[i],u);
        longitud = mayor(longitud,r + max + 1);
        r = mayor(r,max + 1);
    }
    return r;
}

int mayor(int x,int y){
   if(x<y){
        return y;
   }
   else{
        return x;
   }
}


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

FILE *ifp, *ofp ;
int i, j, n, m, extremo[101][101], cont[101], ini, fin, largo ;

int max(int x, int y)
{
    return (x > y ? x : y) ;
}

int altura(int raiz, int inicio)
{
    int i, resultado = 0 ;

    for (i = 0 ; i < cont[raiz] ; i++)
    {
        if (extremo[raiz][i] != ini)
        {
            resultado = max(resultado, 1 + altura(extremo[raiz][i], raiz)) ;
        }
    }

    return resultado ;
}

int diametro(int raiz, int ini)
{
    int altura1 = 0 ;
    int altura2 = 0 ;
    int i, h     = 0 ;

    for (i = 0 ; i < cont[raiz] ; i++)
    {
        if (extremo[raiz][i] != ini)
        {
            h = altura(extremo[raiz][i], raiz) + 1 ;

            if (h > altura1)
            {
                altura2 = altura1 ;
                altura1 = h ;
            }
            else if (h > altura2)
            {
                altura2 = h ;
            }
        }
    }

    h = altura1 + altura2 ;

    for (i = 0 ; i < cont[raiz] ; i++)
    {
        if (extremo[raiz][i] != ini)
        {
            h = max(h, diametro(extremo[raiz][i], raiz)) ;
        }
    }

    return h ;
}

int main(void)
{
    ifp = fopen("input.txt", "r") ;
    ofp = fopen("output.txt", "w") ;

    fscanf(ifp, "%d", &n) ;

    for (i = 0 ; i < n ; i++)
    {
        for (j = 1 ; j <= 100 ; j++)
        {
            cont[j] = 0 ;
        }

        fscanf(ifp, "%d", &m) ;

        for (j = 1 ; j < m ; j++)
        {
            fscanf(ifp, "%d %d", &ini, &fin) ;

            extremo[ini][cont[ini]++] = fin ;
            extremo[fin][cont[fin]++]     = ini ;
        }

        largo += diametro(1, 0) ;
    }

    fprintf(ofp, "%d", largo) ;

    fclose(ifp) ;
    fclose(ofp) ;

    return 0 ;
}


#include <stdio.h>
#include <stdlib.h>
#define CLAVE -1

typedef struct nodoDirectorio{
    int vertice;
    struct nodoAdyacente *lista;
    struct nodoDirectorio *enlace;
    int distancia;

} NodoGrafo;

typedef NodoGrafo* TipoDato;

typedef struct nodo
{
    TipoDato elemento;
    struct nodo *ste;
} Nodo;

void crearPila(Nodo **pila);
void insertar(Nodo **pila,TipoDato elemento);
TipoDato quitar(Nodo **pila);
int pilaVacia(Nodo *pila);

typedef struct nodoAdyacente
{
    struct nodoDirectorio *destino;
    struct nodoAdyacente *enlace;
} NodoLista;

void nuevoVertice(NodoGrafo **grafo, int vertice);
void arista(NodoGrafo *grafo, int org, int dst);
NodoGrafo* direccion(NodoGrafo *grafo,int vert);
void recorreProfundidad(NodoGrafo *grafo,int n, int v, int m[]);

int total = 0;
int longitud = 0;

int main()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    int nro;
    scanf("%d",&nro);
    NodoGrafo *vec[nro];
    int i,x,y,mayor = 0, k,total=0;
    for( k = 0; k < nro; k++)
    {
        vec[k] = NULL;

        int n;
        scanf("%d",&n);

        for( i = 1; i <= n; i++)
        {
            nuevoVertice(&vec[k],i);
        }
        for( i = 1; i <=n-1; i++)
        {
            scanf("%d%d",&x,&y);

            arista(vec[k],x,y);
            arista(vec[k],y,x);

        }
           int m[n];
            mayor = 0;
           longitud = 0;
        for( i = 1; i <= n; i++)
        {
            recorreProfundidad(vec[k],n,i,m);
            if(longitud > mayor){mayor = longitud;}
        }
        total = total + mayor;
    }
            printf("%d",total);

    return 0;

}
void nuevoVertice(NodoGrafo **grafo, int vertice)
{
    NodoGrafo *nuevo;
    nuevo = (NodoGrafo*)malloc(sizeof(NodoGrafo));
    nuevo -> vertice = vertice;
    nuevo -> lista = NULL;
    nuevo -> enlace = *grafo;
    *grafo = nuevo;
}
void arista(NodoGrafo *grafo, int org, int dst)
{
    NodoGrafo *v1,*v2;
    NodoLista *ady;

    v1 = direccion(grafo,org);
    v2 = direccion(grafo,dst);

    if( v1 && v2 )
    {
        ady = (NodoLista*)malloc(sizeof(NodoLista));
        ady -> destino = v2;
        ady -> enlace = v1 -> lista;
        v1 -> lista = ady;
    }
}

NodoGrafo* direccion(NodoGrafo *grafo,int vert)
{
    NodoGrafo *aux;

    aux = grafo;

    while( aux -> vertice != vert && aux != NULL )
    {
        aux = aux -> enlace;
    }
    return aux;

}

void crearPila(Nodo **pila)
{
    *pila = NULL;
}

int pilaVacia(Nodo *pila)
{
    return pila == NULL;
}

void insertar(Nodo **pila,TipoDato elemento)
{
    Nodo *nuevo;

    nuevo = (Nodo*)malloc(sizeof(Nodo));
    nuevo -> elemento = elemento;
    nuevo -> ste = *pila;
    (*pila) = nuevo;
}

TipoDato quitar(Nodo **pila)
{
    TipoDato tem;
    Nodo *q;

    if(pilaVacia(*pila))
    {
        exit(1);
    }

    tem = (*pila) -> elemento;
    q = *pila;
    (*pila) = (*pila) -> ste;
    free(q);

    return tem;
}

void recorreProfundidad(NodoGrafo *grafo,int n, int v, int m[])
{
    NodoGrafo *v1,*v2,*w;
    NodoLista *ady;
    Nodo *pila;

    crearPila(&pila);
    int i;
    int tiempos[n];
    for( i = 0; i < n; i++)
    {
        m[i] = CLAVE;
        tiempos[i] = 0;
    }
    m[v-1] = 0;

    v1 = direccion(grafo,v);
    insertar(&pila,v1);
    total = 0;
    v1 -> distancia = 0;
    while(!pilaVacia(pila))
    {

        w = quitar(&pila);
        ady = w -> lista;
        while(ady != NULL)
        {

            int k;
            k = ady -> destino -> vertice - 1;
            if(m[k] == CLAVE)
            {
                insertar(&pila,ady->destino);
                m[k] = 1;
                ady -> destino -> distancia = w -> distancia + 1;
                if(ady -> destino -> distancia > longitud)
                    longitud = ady -> destino -> distancia;

            }

            ady = ady -> enlace;
        }

    }

}


#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

int n, m, k;
int cnt = 1;
int a[300][300];
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};

void dfs(int i, int j)
{
    if (i < 0 || j < 0 || i == n || j == m)
        return;
    if (a[i][j])
        return;

    cout << i + 1 _ j + 1 << ' ';
    a[i][j] = 1;
    for (int k = 0; k < 4; ++k)
    {
        int xx = i + dx[k];
        int yy = j + dy[k];
        dfs(xx, yy);
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m >> k;
    int ok = k;
    for (int i = 0; i < n; ++i)
    {
        for (int j = 1; j < m; j += 2)
        {
            if (k > 1)
            {
                cout << 2 << ' ';
                cout << i + 1 _ j _ i + 1 _ j + 1 << '\n';
                a[i][j - 1] = a[i][j] = cnt++;
                k--;
            }
        }
    }
    cout << n * m - 2 * (ok - 1) << ' ';
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < m; ++j)
            if (!a[i][j])
                dfs(i, j);
}


#include <bits/stdc++.h>
#include <iostream>
#define FASTIO std::ios::sync_with_stdio(false);
using namespace std;
bool vis[305][305];
int  k, n,m;
void ans(int i, int j, int count){
  if(count+1==k)return ;
  int t=j+2;
  if(t<=m)cout<<2<<" ";
  else if(count-1<k && i<=n){
    ans(i+1, 1, count);
    return;
  }
  while(j<t){
    cout<<i<<" "<<j<<" ";
    vis[i][j]=true;
    j++;
  }
  cout<<endl;
  if(count+1==k)return ;
  ans(i, t, count+1);
}
void dfs(int i, int y){
  vis[i][y]=true;
  cout<<i<<" "<<y<<" ";
  if(y+1<=m && !vis[i][y+1])dfs(i, y+1);
  if(y-1>0 && !vis[i][y-1])dfs(i, y-1);
  if(i+1<=n && !vis[i+1][y])dfs(i+1, y);
  if(i-1>0 && !vis[i-1][y])dfs(i-1, y);

}
int main(){
  FASTIO
  cin>>n>>m>>k;
  memset(vis, false, sizeof(vis));
  ans(1, 1, 0);
  int r=0, x=0, y=0;
  for(int i=1;i<=n;i++){
    for(int j=1;j<=m;j++){
      if(!vis[i][j]){
        if(x==0&& y==0){x=i; y=j;}
        r++;
      }
    }
  }
  cout<<r<<" ";
  dfs(x, y);
}


#include <bits/stdc++.h>
#include <iostream>
#define FASTIO std::ios::sync_with_stdio(false);
using namespace std;
bool vis[405][405];
int  k, n,m;
void ans(int i, int j, int count){
  if(count+1==k)return ;
  int t=j+2;
  if(t<=m){
    cout<<2<<" ";
    while(j<t){
      cout<<i<<" "<<j<<" ";

      vis[i][j]=true;
      j++;
    }
    cout<<endl;
  }
  else if(count-1<k && i+1<=n){
    ans(i+1, 1, count);
    return;
  }

  if(count+1==k)return ;
  ans(i, t, count+1);
}
void dfs(int i, int y){
  vis[i][y]=true;
  cout<<i<<" "<<y<<" ";

  if(y+1<=m && !vis[i][y+1])dfs(i, y+1);
  if(y-1>0 && !vis[i][y-1])dfs(i, y-1);
  if(i+1<=n && !vis[i+1][y])dfs(i+1, y);
  if(i-1>0 && !vis[i-1][y])dfs(i-1, y);

}
int main(){
  FASTIO
  cin>>n>>m>>k;
  memset(vis, false, sizeof(vis));
  ans(1, 1, 0);
  int r=0, x=0, y=0;
  for(int i=1;i<=n;i++){
    for(int j=1;j<=m;j++){
      if(!vis[i][j]){
        if(x==0&& y==0){x=i; y=j;}
        r++;
      }
    }
  }
  cout<<r<<" ";
  dfs(x, y);
}


#include <bits/stdc++.h>
#include <iostream>
#define FASTIO std::ios::sync_with_stdio(false);
using namespace std;
bool vis[405][405];
int  k, n,m;
void ans(int i, int j, int count){
  if(count+1==k)return ;
  int t=j+2;
  if(t<=m)cout<<2<<" ";
  else if(count-1<k && i+1<=n){
    ans(i+1, 1, count);
    return;
  }
  while(j<t){
    cout<<i<<" "<<j<<" ";
    vis[i][j]=true;
    j++;
  }
  cout<<endl;
  if(count+1==k)return ;
  ans(i, t, count+1);
}
void dfs(int i, int y){
  vis[i][y]=true;
  cout<<i<<" "<<y<<" ";
  if(y+1<=m && !vis[i][y+1])dfs(i, y+1);
  if(y-1>0 && !vis[i][y-1])dfs(i, y-1);
  if(i+1<=n && !vis[i+1][y])dfs(i+1, y);
  if(i-1>0 && !vis[i-1][y])dfs(i-1, y);

}
int main(){
  FASTIO
  cin>>n>>m>>k;
  memset(vis, false, sizeof(vis));
  ans(1, 1, 0);
  int r=0, x=0, y=0;
  for(int i=1;i<=n;i++){
    for(int j=1;j<=m;j++){
      if(!vis[i][j]){
        if(x==0&& y==0){x=i; y=j;}
        r++;
      }
    }
  }
  cout<<r<<" ";
  dfs(x, y);
}


#include <bits/stdc++.h>
#include <iostream>
#define FASTIO std::ios::sync_with_stdio(false);
using namespace std;
bool vis[305][305];
int  k, n,m;
void ans(int i, int j, int count){
  if(count+1==k)return ;
  int t=j+2;
  if(t<=m)cout<<2<<" ";
  else if(count-1<k && i+1<=n){
    ans(i+1, 1, count);
    return;
  }
  while(j<t){
    cout<<i<<" "<<j<<" ";
    vis[i][j]=true;
    j++;
  }
  cout<<endl;
  if(count+1==k)return ;
  ans(i, t, count+1);
}
void dfs(int i, int y){
  vis[i][y]=true;
  cout<<i<<" "<<y<<" ";
  if(y+1<=m && !vis[i][y+1])dfs(i, y+1);
  if(y-1>0 && !vis[i][y-1])dfs(i, y-1);
  if(i+1<=n && !vis[i+1][y])dfs(i+1, y);
  if(i-1>0 && !vis[i-1][y])dfs(i-1, y);

}
int main(){
  FASTIO
  cin>>n>>m>>k;
  memset(vis, false, sizeof(vis));
  ans(1, 1, 0);
  int r=0, x=0, y=0;
  for(int i=1;i<=n;i++){
    for(int j=1;j<=m;j++){
      if(!vis[i][j]){
        if(x==0&& y==0){x=i; y=j;}
        r++;
      }
    }
  }
  cout<<r<<" ";
  dfs(x, y);
}


#include <bits/stdc++.h>
#include <iostream>
#define FASTIO std::ios::sync_with_stdio(false);
using namespace std;
int main(){
  FASTIO
  int n, m, k, count=1;
  cin>>n>>m>>k;
  vector<pair<int, int>>v;
  for(int i=1;i<=n;i++){
    for(int j=1;j<=m;j++)v.push_back({i, j});
    i++;
    if(i>n)break;
    for(int j=m;j>0;j--)v.push_back({i, j});
  }
  int j=0;
  for(int i=k;i>0;i--){
    if(i>1){
      int a=j+2;
      cout<<2<<" ";
      for(;j<a;j++)cout<<v[j].first<<" "<<v[j].second<<" ";
      cout<<endl;
      count++;
    }
    if(i==1){
      cout<<v.size()-j<<" ";
      // cout<<count<<" ";
      int a=v.size();
      for(;j<a;j++)cout<<v[j].first<<" "<<v[j].second<<" ";
      exit(0);
    }
  }
}


#include <bits/stdc++.h>
#include <iostream>
#define FASTIO std::ios::sync_with_stdio(false);
using namespace std;
bool vis[405][405];
int  k, n,m, count=0;
void ans(int i, int j, int count){
  if(count+1==k)return ;
  int t=j+2;
  if(i%2==0 && m%2!=0 && !vis[i-1][m]){
    int a=i-1;
    cout<<2;
    while(a<i+1){
      cout<<" "<<a<<" "<<m;
      vis[a][m]=true;
      a++;
    }
    cout<<endl;
    count++;
  }
  if(count+1==k)return ;
  if(t-1<=m){
    cout<<2;
    while(j<t){
      cout<<" "<<i<<" "<<j;
      vis[i][j]=true;
      j++;
    }
    cout<<endl;
  }
  else if(count-1<k && i+1<=n){
    ans(i+1, 1, count);
    return;
  }

  if(count+1==k)return ;
  count++;
  ans(i, t, count);
}

void dfs(int i, int y){
  vis[i][y]=true;
  cout<<" "<<i<<" "<<y;

  if(y+1<=m && !vis[i][y+1])dfs(i, y+1);
  if(y-1>0 && !vis[i][y-1])dfs(i, y-1);
  if(i+1<=n && !vis[i+1][y])dfs(i+1, y);
  if(i-1>0 && !vis[i-1][y])dfs(i-1, y);

}
int main(){
  FASTIO
  cin>>n>>m>>k;
  memset(vis, false, sizeof(vis));
  ans(1, 1, 0);

  int r=0, x=0, y=0;
  for(int i=1;i<=n;i++){
    for(int j=m;j>0;j--){
      if(!vis[i][j]){
        if(x==0&& y==0){x=i; y=j;}
        r++;
      }
    }
  }
  if(r>0){
    cout<<r;
    dfs(x, y);
    cout<<endl;
  }
  return 0;
}


#include <bits/stdc++.h>
#include <iostream>
#define FASTIO std::ios::sync_with_stdio(false);
using namespace std;
bool vis[405][405];
int  k, n,m;
void ans(int i, int j, int count){
  if(count+1==k)return ;
  int t=j+2;
  if(t-1<=m){
    cout<<2<<" ";
    while(j<t){
      cout<<i<<" "<<j<<" ";
      vis[i][j]=true;
      j++;
    }
    cout<<endl;
  }
  else if(count-1<k && i+1<=n){
    ans(i+1, 1, count);
    return;
  }

  if(count+1==k)return ;
  ans(i, t, count+1);
}
void dfs(int i, int y){
  vis[i][y]=true;
  cout<<i<<" "<<y<<" ";

  if(y+1<=m && !vis[i][y+1])dfs(i, y+1);
  if(y-1>0 && !vis[i][y-1])dfs(i, y-1);
  if(i+1<=n && !vis[i+1][y])dfs(i+1, y);
  if(i-1>0 && !vis[i-1][y])dfs(i-1, y);

}
int main(){
  FASTIO
  cin>>n>>m>>k;
  memset(vis, false, sizeof(vis));
  ans(1, 1, 0);
  int r=0, x=0, y=0;
  for(int i=1;i<=n;i++){
    for(int j=1;j<=m;j++){
      if(!vis[i][j]){
        if(x==0&& y==0){x=i; y=j;}
        r++;
      }
    }
  }
  cout<<r<<" ";
  dfs(x, y);
  cout<<endl;
  return 0;
}


#include <bits/stdc++.h>
#include <iostream>
#define FASTIO std::ios::sync_with_stdio(false);
using namespace std;
bool vis[405][405];
int  k, n,m, count=0;
void ans(int i, int j, int count){
  if(count+1==k)return ;
  int t=j+2;
  if(i%2==0 && m%2!=0 && !vis[i-1][m]){
    int a=i-1;
    cout<<count+1;
    while(a<i+1){
      cout<<" "<<a<<" "<<m;
      vis[a][m]=true;
      a++;
    }
    cout<<endl;
    count++;
  }
  if(count+1==k)return ;
  if(t-1<=m){
    cout<<count+1;
    while(j<t){
      cout<<" "<<i<<" "<<j;
      vis[i][j]=true;
      j++;
    }
    cout<<endl;
  }
  else if(count-1<k && i+1<=n){
    ans(i+1, 1, count);
    return;
  }

  if(count+1==k)return ;
  count++;
  ans(i, t, count);
}

void dfs(int i, int y){
  vis[i][y]=true;
  cout<<" "<<i<<" "<<y;

  if(y+1<=m && !vis[i][y+1])dfs(i, y+1);
  if(y-1>0 && !vis[i][y-1])dfs(i, y-1);
  if(i+1<=n && !vis[i+1][y])dfs(i+1, y);
  if(i-1>0 && !vis[i-1][y])dfs(i-1, y);

}
int main(){
  FASTIO
  cin>>n>>m>>k;
  memset(vis, false, sizeof(vis));
  ans(1, 1, 0);

  int r=0, x=0, y=0;
  for(int i=1;i<=n;i++){
    for(int j=1;j<=m;j++){
      if(!vis[i][j]){
        if(x==0&& y==0){x=i; y=j;}
        r++;
      }
    }
  }
  cout<<r;
  dfs(x, y);
  cout<<endl;
  return 0;
}


#include <bits/stdc++.h>
#include <iostream>
#define FASTIO std::ios::sync_with_stdio(false);
using namespace std;
bool vis[405][405];
int  k, n,m, count=0;
void ans(int i, int j, int count){
  if(count+1==k)return ;
  int t=j+2;
  if(i%2==0 && m%2!=0 && !vis[i-1][m]){
    int a=i-1;
    cout<<count+1;
    while(a<i+1){
      cout<<" "<<a<<" "<<m;
      vis[a][m]=true;
      a++;
    }
    cout<<endl;
    count++;
  }
  if(count+1==k)return ;
  if(t-1<=m){
    cout<<count+1;
    while(j<t){
      cout<<" "<<i<<" "<<j;
      vis[i][j]=true;
      j++;
    }
    cout<<endl;
  }
  else if(count-1<k && i+1<=n){
    ans(i+1, 1, count);
    return;
  }

  if(count+1==k)return ;
  count++;
  ans(i, t, count);
}

void dfs(int i, int y){
  vis[i][y]=true;
  cout<<" "<<i<<" "<<y;

  if(y+1<=m && !vis[i][y+1])dfs(i, y+1);
  if(y-1>0 && !vis[i][y-1])dfs(i, y-1);
  if(i+1<=n && !vis[i+1][y])dfs(i+1, y);
  if(i-1>0 && !vis[i-1][y])dfs(i-1, y);

}
int main(){
  FASTIO
  cin>>n>>m>>k;
  memset(vis, false, sizeof(vis));
  ans(1, 1, 0);

  int r=0, x=0, y=0;
  for(int i=1;i<=n;i++){
    for(int j=m;j>0;j--){
      if(!vis[i][j]){
        if(x==0&& y==0){x=i; y=j;}
        r++;
      }
    }
  }
  cout<<r;
  dfs(x, y);
  cout<<endl;
  return 0;
}


#include <bits/stdc++.h>
#include <iostream>
#define FASTIO std::ios::sync_with_stdio(false);
using namespace std;
bool vis[405][405];
int  k, n,m, count=0;
void ans(int i, int j, int count){
  if(count+1==k)return ;
  int t=j+2;
  if(t-1<=m){
    cout<<2;
    while(j<t){
      cout<<" "<<i<<" "<<j;
      vis[i][j]=true;
      j++;
    }
    cout<<endl;
  }
  else if(count-1<k && i+1<=n){
    ans(i+1, 1, count);
    return;
  }

  if(count+1==k)return ;
  count++;
  ans(i, t, count);
}
void ans1(int i, int j, int count){
  if(count+1==k)return ;
  int t=i+2;
  if(t-1<=n){
    cout<<2;
    while(i<t){
      cout<<" "<<i<<" "<<j;
      vis[i][j]=true;
      i++;
    }
    cout<<endl;
  }
  else return ;
  if(count+1==k)return ;
  count++;
  ans1(t, j, count);
}
void dfs(int i, int y){
  vis[i][y]=true;
  cout<<" "<<i<<" "<<y;

  if(y+1<=m && !vis[i][y+1])dfs(i, y+1);
  if(y-1>0 && !vis[i][y-1])dfs(i, y-1);
  if(i+1<=n && !vis[i+1][y])dfs(i+1, y);
  if(i-1>0 && !vis[i-1][y])dfs(i-1, y);

}
int main(){
  FASTIO
  cin>>n>>m>>k;
  memset(vis, false, sizeof(vis));
  ans(1, 1, 0);
  int count=n*(m/2);
  if(count+1<k){
    ans1(1, m, count);
  }
  int r=0, x=0, y=0;
  for(int i=1;i<=n;i++){
    for(int j=1;j<=m;j++){
      if(!vis[i][j]){
        if(x==0&& y==0){x=i; y=j;}
        r++;
      }
    }
  }
  cout<<r;
  dfs(x, y);
  cout<<endl;
  return 0;
}


#include <bits/stdc++.h>
#include <iostream>
#define FASTIO std::ios::sync_with_stdio(false);
using namespace std;
bool vis[405][405];
int  k, n,m;
void ans(int i, int j, int count){
  if(count+1==k)return ;
  int t=j+2;
  if(t-1<=m){
    cout<<2;
    while(j<t){
      cout<<" "<<i<<" "<<j;
      vis[i][j]=true;
      j++;
    }
    cout<<endl;
  }
  else if(count-1<k && i+1<=n){
    ans(i+1, 1, count);
    return;
  }

  if(count+1==k)return ;
  ans(i, t, count+1);
}
void dfs(int i, int y){
  vis[i][y]=true;
  cout<<" "<<i<<" "<<y;

  if(y+1<=m && !vis[i][y+1])dfs(i, y+1);
  if(y-1>0 && !vis[i][y-1])dfs(i, y-1);
  if(i+1<=n && !vis[i+1][y])dfs(i+1, y);
  if(i-1>0 && !vis[i-1][y])dfs(i-1, y);

}
int main(){
  FASTIO
  cin>>n>>m>>k;
  memset(vis, false, sizeof(vis));
  ans(1, 1, 0);
  int r=0, x=0, y=0;
  for(int i=1;i<=n;i++){
    for(int j=1;j<=m;j++){
      if(!vis[i][j]){
        if(x==0&& y==0){x=i; y=j;}
        r++;
      }
    }
  }
  cout<<r;
  dfs(x, y);
  cout<<endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long

int n,m,k;
int l,c;
int v[500][500];
vector < pair<int,int> > ans[100005];

void dfs(int x, int y)
{
	if(x<1 || y<1 || x>n || y>m)
		return;
	if(v[x][y])
	    return;
	c++;
	if(c>2 && l<k)
		return;
	v[x][y]=l;
	ans[l].push_back({x, y});
	dfs(x, y+1);
	dfs(x+1, y);
	dfs(x, y-1);
	dfs(x-1, y);
}

int32_t main()
{
	FastIO;
	cin>>n>>m>>k;
	for(int i=1; i<=n; i++)
	{
		for(int j=1; j<=m; j++)
		{
			if(v[i][j]==0)
			{
				c=0;
				l++;
				dfs(i, j);
			}
		}
	}

/*	for(int i=1; i<=n; i++)
	{
		for(int j=1; j<=m; j++)
			cout<<v[i][j]<<" ";
		cout<<"\n";
	}
*/
	for(int i=1; i<=k; i++)
	{
	    cout<<ans[i].size()<<" ";
	    for(auto &x : ans[i])
	        cout<<x.first<<" "<<x.second<<" ";
	    cout<<"\n";
	}
}


#include <bits/stdc++.h>
using namespace std;
#define FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long

int n,m,k;
int l,c;
int v[500][500];
vector < pair<int,int> > ans[100005];

void dfs(int x, int y)
{
	if(x<1 || y<1 || x>n || y>m)
		return;
	if(v[x][y])
	    return;
	c++;
	if(c>2 && l<k)
	{
		l++;
		c=1;
	}

	v[x][y]=l;
	ans[l].push_back({x, y});
	dfs(x+1, y);
	dfs(x, y+1);
	dfs(x-1, y);
	dfs(x, y-1);
}

int32_t main()
{
	FastIO;
	cin>>n>>m>>k;
	for(int i=1; i<=n; i++)
	{
		for(int j=1; j<=m; j++)
		{
			if(v[i][j]==0)
			{
				c=0;
				l++;
				dfs(i, j);
			}
		}
	}

/*	for(int i=1; i<=n; i++)
	{
		for(int j=1; j<=m; j++)
			cout<<v[i][j]<<" ";
		cout<<"\n";
	}
*/
	for(int i=1; i<=k; i++)
	{
	    cout<<ans[i].size()<<" ";
	    for(auto &x : ans[i])
	        cout<<x.first<<" "<<x.second<<" ";
	    cout<<"\n";
	}
}


#include <bits/stdc++.h>
using namespace std;
#define FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long

int n,m,k;
int l=1,c;
int v[500][500];
vector < pair<int,int> > ans[100005];

void dfs(int x, int y)
{
	if(x<1 || y<1 || x>n || y>m)
		return;
	if(v[x][y])
	    return;
	c++;
	if(c>2 && l<k)
	{
		l++;
		c=1;
	}

	v[x][y]=l;
	ans[l].push_back({x, y});
	dfs(x+1, y);
	dfs(x, y+1);
	dfs(x-1, y);
	dfs(x, y-1);
}

int32_t main()
{
	FastIO;
	cin>>n>>m>>k;

	dfs(1, 1);
	for(int i=1; i<=k; i++)
	{
	    cout<<ans[i].size()<<" ";
	    for(auto &x : ans[i])
	        cout<<x.first<<" "<<x.second<<" ";
	    cout<<"\n";
	}
}


#include <bits/stdc++.h>
using namespace std;
#define FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long

int n,m,k;
int l,c;
int v[500][500];
vector < pair<int,int> > ans[100005];

void dfs(int x, int y)
{
	if(x<1 || y<1 || x>n || y>m)
		return;
	if(v[x][y])
	    return;
	c++;
	if(c>2 && l<k)
		return;
	v[x][y]=l;
	ans[l].push_back({x, y});
	dfs(x+1, y);
	dfs(x, y+1);
	dfs(x-1, y);
	dfs(x, y-1);
}

int32_t main()
{
	FastIO;
	cin>>n>>m>>k;
	for(int i=1; i<=n; i++)
	{
		for(int j=1; j<=m; j++)
		{
			if(v[i][j]==0)
			{
				c=0;
				l++;
				dfs(i, j);
			}
		}
	}

/*	for(int i=1; i<=n; i++)
	{
		for(int j=1; j<=m; j++)
			cout<<v[i][j]<<" ";
		cout<<"\n";
	}
*/
	for(int i=1; i<=k; i++)
	{
	    cout<<ans[i].size()<<" ";
	    for(auto &x : ans[i])
	        cout<<x.first<<" "<<x.second<<" ";
	    cout<<"\n";
	}
}


#include <bits/stdc++.h>
using namespace std;
#define FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long

int n,m,k;
int l,c;
int v[305][305];
vector < pair<int,int> > ans[100005];

void dfs(int x, int y)
{
	if(x<1 || y<1 || x>n || y>m)
		return;
	if(v[x][y])
	    return;
	c++;
	if(c>2 && l<k)
	{
		l++;
		c=1;
	}

	v[x][y]=l;
	ans[l].push_back({x, y});
	dfs(x+1, y);
	dfs(x, y+1);
	dfs(x-1, y);
	dfs(x, y-1);
}

int32_t main()
{
	FastIO;
	cin>>n>>m>>k;

    dfs(1,1);
	for(int i=1; i<=k; i++)
	{
	    cout<<ans[i].size()<<" ";
	    for(auto &x : ans[i])
	        cout<<x.first<<" "<<x.second<<" ";
	    cout<<"\n";
	}
}


#include <iostream>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <iterator>
#include <map>
#include <numeric>
#include <stdio.h>
#include <math.h>
#include <list>
#define ll long long int
#define pi pair<int,int>
using namespace std;
int inp[300 + 7][300 + 7];
vector<pi> out[300+1];
int main()
{
	ios_base::sync_with_stdio(false);
	int n, m, k;
	cin >> n >> m >> k;
	for (int i = 0; i < n;i++)
		for (int j = 0; j < m;j++)
			inp[i][j] = 0;

	//asign tuubes
	int currRow = 0, currCol = 0;
	int tempRow= -1,last_k = -1;
	//fill rows
	int tube = 1;
	while (tube <= k)
	{
		if (currCol + 1 == m)
			break;
		inp[currRow][currCol] = inp[currRow][currCol + 1] = tube;
		tube++;
		currRow++;

		if (currRow == n)
		{
			currRow = 0;
			currCol += 2;
		}
	}
	//tube++;
	while (tube <= k)
	{

		inp[currRow][currCol] = inp[currRow+1][currCol] = tube;
		tube++;
		currRow += 2;
	}

	for (int i = 0; i < n;i++)
	{
		for (int j = 0; j < m;j++)
		{
			if (inp[i][j] == 0)
			{
				if (j - 1 >= 0)
				{
					inp[i][j] = inp[i][j - 1];
					//lastK = inp[i][j];
				}
				else
				{
					inp[i][j] = inp[i-1][j];
				}
			}
		}
	}
	int row,col;
	bool check = false, flag = false;
	if (k < n)
		check = true;
	for (int i = 0; i < n;i++)
	{

		for (int j = 0;j < m;j++)
		{
			if (check && inp[i][j] == k)
			{
				flag = true;
				row = i;
				col = j;
				break;
			}
			out[inp[i][j]].push_back({ i + 1,j + 1 });

		}
		if (flag)
			break;
	}
	if (check)
	{
		int dir = 1;

		for (int i = row;i < n;i++)
		{
			if (dir == 1)
			{
				col = 0;
			}
			else
				col = m - 1;

			while (col >= 0 && col < m)
			{
				out[inp[i][col]].push_back({ i + 1,col + 1 });
				if (dir == 1)
					col++;
				else
					col--;
			}
			dir = 1 - dir;

		}
	}
	for (int i = 1; i <= k;i++)
	{
		cout << out[i].size() << " ";
		for (int j = 0; j < out[i].size();j++)
			cout << out[i][j].first << " " << out[i][j].second << " ";
		cout << endl;
	}
	return 0;
}


#include <iostream>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <iterator>
#include <map>
#include <numeric>
#include <stdio.h>
#include <math.h>
#include <list>
#define ll long long int
#define pi pair<int,int>
using namespace std;
int inp[300 + 7][300 + 7];
vector<pi> out[45000+1];
int main()
{
	ios_base::sync_with_stdio(false);
	int n, m, k;
	cin >> n >> m >> k;
	for (int i = 0; i < n;i++)
		for (int j = 0; j < m;j++)
			inp[i][j] = 0;

	//asign tuubes
	int currRow = 0, currCol = 0;
	int tempRow= -1,last_k = -1;
	//fill rows
	int tube = 1;
	while (tube <= k)
	{
		if (currCol + 1 == m)
			break;
		inp[currRow][currCol] = inp[currRow][currCol + 1] = tube;
		tube++;
		currRow++;

		if (currRow == n)
		{
			currRow = 0;
			currCol += 2;
		}
	}
	//tube++;
	while (tube <= k)
	{

		inp[currRow][currCol] = inp[currRow+1][currCol] = tube;
		tube++;
		currRow += 2;
	}

	for (int i = 0; i < n;i++)
	{
		for (int j = 0; j < m;j++)
		{
			if (inp[i][j] == 0)
			{
				if (j - 1 >= 0)
				{
					inp[i][j] = inp[i][j - 1];
					//lastK = inp[i][j];
				}
				else
				{
					inp[i][j] = inp[i-1][j];
				}
			}
		}
	}
	int row,col;
	bool check = false, flag = false;
	if (k < n)
		check = true;
	for (int i = 0; i < n;i++)
	{

		for (int j = 0;j < m;j++)
		{
			if (check && inp[i][j] == k)
			{
				flag = true;
				row = i;
				col = j;
				break;
			}
			out[inp[i][j]].push_back({ i + 1,j + 1 });

		}
		if (flag)
			break;
	}
	if (check)
	{
		int dir = 1;

		for (int i = row;i < n;i++)
		{
			if (dir == 1)
			{
				col = 0;
			}
			else
				col = m - 1;

			while (col >= 0 && col < m)
			{
				out[inp[i][col]].push_back({ i + 1,col + 1 });
				if (dir == 1)
					col++;
				else
					col--;
			}
			dir = 1 - dir;

		}
	}
	for (int i = 1; i <= k;i++)
	{
		cout << out[i].size() << " ";
		for (int j = 0; j < out[i].size();j++)
			cout << out[i][j].first << " " << out[i][j].second << " ";
		cout << endl;
	}
	return 0;
}


#include <iostream>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <iterator>
#include <map>
#include <numeric>
#include <stdio.h>
#include <math.h>
#include <list>
#define ll long long int
#define pi pair<int,int>
using namespace std;
int inp[300 + 7][300 + 7];
vector<pi> out[300+1];
int main()
{
	ios_base::sync_with_stdio(false);
	int n, m, k;
	cin >> n >> m >> k;
	for (int i = 0; i < n;i++)
		for (int j = 0; j < m;j++)
			inp[i][j] = 0;

	//asign tuubes
	int currRow = 0, currCol = 0;
	int tempRow= -1,last_k = -1;
	for (int tube = 1; tube <= k;tube++)
	{
		inp[currRow][currCol] = inp[currRow][currCol + 1] = tube;

		currRow++;

		if (currRow == n)
		{
			currRow = 0;
			currCol += 2;
		}
	}
	int lastK = -1;
	for (int i = 0; i < n;i++)
	{
		for (int j = 0; j < m;j++)
		{
			if (inp[i][j] == 0)
			{
				if (j - 1 >= 0)
				{
					inp[i][j] = inp[i][j - 1];
					lastK = inp[i][j];
				}
				else
				{
					inp[i][j] = inp[i-1][j];
				}
			}
		}
	}
	int row,col;
	bool check = false, flag = false;
	if (k < n)
		check = true;
	for (int i = 0; i < n;i++)
	{

		for (int j = 0;j < m;j++)
		{
			if (check && inp[i][j] == k)
			{
				flag = true;
				row = i;
				col = j;
				break;
			}
			out[inp[i][j]].push_back({ i + 1,j + 1 });

		}
		if (flag)
			break;
	}
	if (check)
	{
		int dir = 1;

		for (int i = row;i < n;i++)
		{
			if (dir == 1)
			{
				col = 0;
			}
			else
				col = m - 1;

			while (col >= 0 && col < m)
			{
				out[inp[i][col]].push_back({ i + 1,col + 1 });
				if (dir == 1)
					col++;
				else
					col--;
			}
			dir = 1 - dir;

		}
	}
	for (int i = 1; i <= k;i++)
	{
		cout << out[i].size() << " ";
		for (int j = 0; j < out[i].size();j++)
			cout << out[i][j].first << " " << out[i][j].second << " ";
		cout << endl;
	}
	return 0;
}


#include <iostream>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <iterator>
#include <map>
#include <numeric>
#include <stdio.h>
#include <math.h>
#include <list>
#define ll long long int
#define pi pair<int,int>
using namespace std;
int inp[300 + 7][300 + 7];
vector<pi> out[300];
int main()
{
	ios_base::sync_with_stdio(false);
	int n, m, k;
	cin >> n >> m >> k;
	for (int i = 0; i < n;i++)
		for (int j = 0; j < m;j++)
			inp[i][j] = 0;

	//asign tuubes
	int currRow = 0, currCol = 0;
	int tempRow= -1,last_k = -1;
	for (int tube = 1; tube <= k;tube++)
	{
		inp[currRow][currCol] = inp[currRow][currCol + 1] = tube;

		currRow++;

		if (currRow == n)
		{
			currRow = 0;
			currCol += 2;
		}
	}
	int lastK = -1;
	for (int i = 0; i < n;i++)
	{
		for (int j = 0; j < m;j++)
		{
			if (inp[i][j] == 0)
			{
				if (j - 1 >= 0)
				{
					inp[i][j] = inp[i][j - 1];
					lastK = inp[i][j];
				}
				else
				{
					inp[i][j] = inp[i-1][j];
				}
			}
		}
	}
	int row,col;
	bool check = false, flag = false;
	if (k < n)
		check = true;
	for (int i = 0; i < n;i++)
	{

		for (int j = 0;j < m;j++)
		{
			if (check && inp[i][j] == k)
			{
				flag = true;
				row = i;
				col = j;
				break;
			}
			out[inp[i][j]].push_back({ i + 1,j + 1 });

		}
		if (flag)
			break;
	}
	if (check)
	{
		int dir = 1;

		for (int i = row;i < n;i++)
		{
			if (dir == 1)
			{
				col = 0;
			}
			else
				col = m - 1;

			while (col >= 0 && col < m)
			{
				out[inp[i][col]].push_back({ i + 1,col + 1 });
				if (dir == 1)
					col++;
				else
					col--;
			}
			dir = 1 - dir;

		}
	}
	for (int i = 1; i <= k;i++)
	{
		cout << out[i].size() << " ";
		for (int j = 0; j < out[i].size();j++)
			cout << out[i][j].first << " " << out[i][j].second << " ";
		cout << endl;
	}
	return 0;
}


#include <iostream>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <iterator>
#include <map>
#include <numeric>
#include <stdio.h>
#include <math.h>
#include <list>
#define ll long long int
#define pi pair<int,int>
using namespace std;
int inp[300 + 7][300 + 7];
vector<pi> out[4500+1];
int main()
{
	ios_base::sync_with_stdio(false);
	int n, m, k;
	cin >> n >> m >> k;
	for (int i = 0; i < n;i++)
		for (int j = 0; j < m;j++)
			inp[i][j] = 0;

	//asign tuubes
	int currRow = 0, currCol = 0;
	int tempRow= -1,last_k = -1;
	//fill rows
	int tube = 1;
	while (tube <= k)
	{
		if (currCol + 1 == m)
			break;
		inp[currRow][currCol] = inp[currRow][currCol + 1] = tube;
		tube++;
		currRow++;

		if (currRow == n)
		{
			currRow = 0;
			currCol += 2;
		}
	}
	//tube++;
	while (tube <= k)
	{

		inp[currRow][currCol] = inp[currRow+1][currCol] = tube;
		tube++;
		currRow += 2;
	}

	for (int i = 0; i < n;i++)
	{
		for (int j = 0; j < m;j++)
		{
			if (inp[i][j] == 0)
			{
				if (j - 1 >= 0)
				{
					inp[i][j] = inp[i][j - 1];
					//lastK = inp[i][j];
				}
				else
				{
					inp[i][j] = inp[i-1][j];
				}
			}
		}
	}
	int row,col;
	bool check = false, flag = false;
	if (k < n)
		check = true;
	for (int i = 0; i < n;i++)
	{

		for (int j = 0;j < m;j++)
		{
			if (check && inp[i][j] == k)
			{
				flag = true;
				row = i;
				col = j;
				break;
			}
			out[inp[i][j]].push_back({ i + 1,j + 1 });

		}
		if (flag)
			break;
	}
	if (check)
	{
		int dir = 1;

		for (int i = row;i < n;i++)
		{
			if (dir == 1)
			{
				col = 0;
			}
			else
				col = m - 1;

			while (col >= 0 && col < m)
			{
				out[inp[i][col]].push_back({ i + 1,col + 1 });
				if (dir == 1)
					col++;
				else
					col--;
			}
			dir = 1 - dir;

		}
	}
	for (int i = 1; i <= k;i++)
	{
		cout << out[i].size() << " ";
		for (int j = 0; j < out[i].size();j++)
			cout << out[i][j].first << " " << out[i][j].second << " ";
		cout << endl;
	}
	return 0;
}


/*//DJ aka Dvij Joshi

            **************            *********************
            ****************          *********************
            ******      ******                   *****
            ******        ******                 *****
            ******        ******                 *****
            ******        ******                 *****
            ******        ******                 *****
            ******        ******       *****     *****
            ******       ******        *****     *****
            ******      ******         *****     *****
            ****************           ******* *******
            **************              *************
*/
//HEADERS---------------------------------
#include<bits/stdc++.h>
//MACROS---------------------------------
#define hell 1000000007
#define vi  vector<int>
#define vii vector<pair<int,int>>
#define vll vector<long long>
#define vc  vector<char>
#define vs  vector<string>
#define all(v) v.begin(),v.end()
#define mii map<int,int>
#define mll map<long long,long long>
#define mci map<char,int>
#define pii pair<int,int>
#define msi map<string,int>
#define loop(i,a,b) for(i=a;i<b;++i)
#define rloop(i,a,b) for(i=a;i>b;--i)
#define in(i,a,n) for(i=0;i<n;++i) cin>>a[i];
#define out(i,a,n) for(i=0;i<n;++i) cout<<a[i]<<" ";
#define ll long long
#define sp(n) setprecision(n)
#define fin freopen( "input.txt", "r", stdin );
#define fout freopen( "output.txt", "w", stdout );
#define outall(a) loop(i,0,sizeof(a)/sizeof(a[0])) cout<<a[i]<<" "; cout<<endl
#define endl "\n"
#define int long long
using namespace std;
const long double pi=acos(-1.0);
//GLOBALS--------------------------------------
mii m1;
//FUNCTIONS------------------------------------
// Binary search (note boundaries in the caller)
int CeilIndex(std::vector<int>& v, int l, int r, int key)
{
	while (r - l > 1) {
		int m = l + (r - l) / 2;
		if (v[m] >= key)
			r = m;
		else
			l = m;
	}

	return r;
}

int LongestIncreasingSubsequenceLength(std::vector<int>& v)
{
	if (v.size() == 0)
		return 0;

	std::vector<int> tail(v.size(), 0);
	int length = 1; // always points empty slot in tail

	tail[0] = v[0];
	for (size_t i = 1; i < v.size(); i++) {

		// new smallest value
		if (v[i] < tail[0])
			tail[0] = v[i];

		// v[i] extends largest subsequence
		else if (v[i] > tail[length - 1])
			tail[length++] = v[i];

		// v[i] will become end candidate of an existing
		// subsequence or Throw away larger elements in all
		// LIS, to make room for upcoming grater elements
		// than v[i] (and also, v[i] would have already
		// appeared in one of LIS, identify the location
		// and replace it)
		else
			tail[CeilIndex(tail, -1, length - 1, v[i])] = v[i];
	}

	return length;
}
ll powm(ll a,ll b, ll m)
{
	if(b==0) return 1;
	ll t=powm(a,b/2,m);
	if(b%2) return a*t%m*t%m;
	return t*t%m;
}
ll modinv1(ll b, ll m)
{
	return powm(b,m-2,m);
}
bool comp(const pii &p1,const pii &p2)
{
	if(p1.second==p2.second) return (p1.first<p2.first);
	return (p1.second<p2.second);
}
ll modinv(ll n,ll m)
{
	ll i=0;
	loop(i,1,m) if((n*i)%m==1) return i;
}
void DJ()
{
	int n,m,k,dir=1,i,j;
	cin>>n>>m>>k;
	int arr[n+1][m+1]={0};
	int x=n*m,y=n*m/k,cx=1,cy=1;
	while(x/k>1)
	{
		cout<<y<<' ';
		loop(i,0,y)
		{
			if(cy==0&&dir==-1)
			{
				cx++; cy++;
				dir=1;
			}
			if(cy==m+1&&dir==1)
			{
				cx++; cy--;
				dir=-1;
			}
			if(dir==1)
			{
				arr[cx][cy]=1;
				cout<<cx<<' '<<cy++<<' ';
			}
			else
			{
				arr[cx][cy]=1;
				cout<<cx<<' '<<cy--<<' ';
			}
		}
		cout<<endl;
		x-=y;
	}
	cout<<x<<' ';
	while(x--)
	{
		if(cy==0&&dir==-1)
		{
			cx++; cy++;
			dir=1;
		}
		if(cy==m+1&&dir==1)
		{
			cx++; cy--;
			dir=-1;
		}
		if(dir==1)
		{
			arr[cx][cy]=1;
			cout<<cx<<' '<<cy++<<' ';
		}
		if(dir==-1)
		{
			arr[cx][cy]=1;
			cout<<cx<<' '<<cy--<<' ';

		}
	}
}
//MAIN FUNCTION--------------------------------
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll t=1;
	// cin>>t;
	// fin fout
	while(t--) DJ();
	return 0;
}


/*//DJ aka Dvij Joshi

            **************            *********************
            ****************          *********************
            ******      ******                   *****
            ******        ******                 *****
            ******        ******                 *****
            ******        ******                 *****
            ******        ******                 *****
            ******        ******       *****     *****
            ******       ******        *****     *****
            ******      ******         *****     *****
            ****************           ******* *******
            **************              *************
*/
//HEADERS---------------------------------
#include<bits/stdc++.h>
//MACROS---------------------------------
#define hell 1000000007
#define vi  vector<int>
#define vii vector<pair<int,int>>
#define vll vector<long long>
#define vc  vector<char>
#define vs  vector<string>
#define all(v) v.begin(),v.end()
#define mii map<int,int>
#define mll map<long long,long long>
#define mci map<char,int>
#define pii pair<int,int>
#define msi map<string,int>
#define loop(i,a,b) for(i=a;i<b;++i)
#define rloop(i,a,b) for(i=a;i>b;--i)
#define in(i,a,n) for(i=0;i<n;++i) cin>>a[i];
#define out(i,a,n) for(i=0;i<n;++i) cout<<a[i]<<" ";
#define ll long long
#define sp(n) setprecision(n)
#define fin freopen( "input.txt", "r", stdin );
#define fout freopen( "output.txt", "w", stdout );
#define outall(a) loop(i,0,sizeof(a)/sizeof(a[0])) cout<<a[i]<<" "; cout<<endl
#define endl "\n"
#define int long long
using namespace std;
const long double pi=acos(-1.0);
//GLOBALS--------------------------------------
mii m1;
//FUNCTIONS------------------------------------
// Binary search (note boundaries in the caller)
int CeilIndex(std::vector<int>& v, int l, int r, int key)
{
	while (r - l > 1) {
		int m = l + (r - l) / 2;
		if (v[m] >= key)
			r = m;
		else
			l = m;
	}

	return r;
}

int LongestIncreasingSubsequenceLength(std::vector<int>& v)
{
	if (v.size() == 0)
		return 0;

	std::vector<int> tail(v.size(), 0);
	int length = 1; // always points empty slot in tail

	tail[0] = v[0];
	for (size_t i = 1; i < v.size(); i++) {

		// new smallest value
		if (v[i] < tail[0])
			tail[0] = v[i];

		// v[i] extends largest subsequence
		else if (v[i] > tail[length - 1])
			tail[length++] = v[i];

		// v[i] will become end candidate of an existing
		// subsequence or Throw away larger elements in all
		// LIS, to make room for upcoming grater elements
		// than v[i] (and also, v[i] would have already
		// appeared in one of LIS, identify the location
		// and replace it)
		else
			tail[CeilIndex(tail, -1, length - 1, v[i])] = v[i];
	}

	return length;
}
ll powm(ll a,ll b, ll m)
{
	if(b==0) return 1;
	ll t=powm(a,b/2,m);
	if(b%2) return a*t%m*t%m;
	return t*t%m;
}
ll modinv1(ll b, ll m)
{
	return powm(b,m-2,m);
}
bool comp(const pii &p1,const pii &p2)
{
	if(p1.second==p2.second) return (p1.first<p2.first);
	return (p1.second<p2.second);
}
ll modinv(ll n,ll m)
{
	ll i=0;
	loop(i,1,m) if((n*i)%m==1) return i;
}
void DJ()
{
	int n,m,k,dir=1,i,j;
	cin>>n>>m>>k;
	int arr[n+1][m+1]={0};
	int x=n*m,y=n*m/k,cx=1,cy=1;
	while(x>y+n*m%k)
	{
		cout<<y<<' ';
		loop(i,0,y)
		{
			if(cy==0&&dir==-1)
			{
				cx++; cy++;
				dir=1;
			}
			if(cy==m+1&&dir==1)
			{
				cx++; cy--;
				dir=-1;
			}
			if(dir==1)
			{
				arr[cx][cy]=1;
				cout<<cx<<' '<<cy++<<' ';
			}
			else
			{
				arr[cx][cy]=1;
				cout<<cx<<' '<<cy--<<' ';
			}
		}
		cout<<endl;
		x-=y;
	}
	if(!x) return;
	cout<<x<<' ';
	while(x--)
	{
		if(cy==0&&dir==-1)
		{
			cx++; cy++;
			dir=1;
		}
		if(cy==m+1&&dir==1)
		{
			cx++; cy--;
			dir=-1;
		}
		if(dir==1)
		{
			arr[cx][cy]=1;
			cout<<cx<<' '<<cy++<<' ';
		}
		if(dir==-1)
		{
			arr[cx][cy]=1;
			cout<<cx<<' '<<cy--<<' ';

		}
	}
}
//MAIN FUNCTION--------------------------------
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll t=1;
	// cin>>t;
	// fin fout
	while(t--) DJ();
	return 0;
}


/*//DJ aka Dvij Joshi

            **************            *********************
            ****************          *********************
            ******      ******                   *****
            ******        ******                 *****
            ******        ******                 *****
            ******        ******                 *****
            ******        ******                 *****
            ******        ******       *****     *****
            ******       ******        *****     *****
            ******      ******         *****     *****
            ****************           ******* *******
            **************              *************
*/
//HEADERS---------------------------------
#include<bits/stdc++.h>
//MACROS---------------------------------
#define hell 1000000007
#define vi  vector<int>
#define vii vector<pair<int,int>>
#define vll vector<long long>
#define vc  vector<char>
#define vs  vector<string>
#define all(v) v.begin(),v.end()
#define mii map<int,int>
#define mll map<long long,long long>
#define mci map<char,int>
#define pii pair<int,int>
#define msi map<string,int>
#define loop(i,a,b) for(i=a;i<b;++i)
#define rloop(i,a,b) for(i=a;i>b;--i)
#define in(i,a,n) for(i=0;i<n;++i) cin>>a[i];
#define out(i,a,n) for(i=0;i<n;++i) cout<<a[i]<<" ";
#define ll long long
#define sp(n) setprecision(n)
#define fin freopen( "input.txt", "r", stdin );
#define fout freopen( "output.txt", "w", stdout );
#define outall(a) loop(i,0,sizeof(a)/sizeof(a[0])) cout<<a[i]<<" "; cout<<endl
#define endl "\n"
#define int long long
using namespace std;
const long double pi=acos(-1.0);
//GLOBALS--------------------------------------
mii m1;
//FUNCTIONS------------------------------------
// Binary search (note boundaries in the caller)
int CeilIndex(std::vector<int>& v, int l, int r, int key)
{
	while (r - l > 1) {
		int m = l + (r - l) / 2;
		if (v[m] >= key)
			r = m;
		else
			l = m;
	}

	return r;
}

int LongestIncreasingSubsequenceLength(std::vector<int>& v)
{
	if (v.size() == 0)
		return 0;

	std::vector<int> tail(v.size(), 0);
	int length = 1; // always points empty slot in tail

	tail[0] = v[0];
	for (size_t i = 1; i < v.size(); i++) {

		// new smallest value
		if (v[i] < tail[0])
			tail[0] = v[i];

		// v[i] extends largest subsequence
		else if (v[i] > tail[length - 1])
			tail[length++] = v[i];

		// v[i] will become end candidate of an existing
		// subsequence or Throw away larger elements in all
		// LIS, to make room for upcoming grater elements
		// than v[i] (and also, v[i] would have already
		// appeared in one of LIS, identify the location
		// and replace it)
		else
			tail[CeilIndex(tail, -1, length - 1, v[i])] = v[i];
	}

	return length;
}
ll powm(ll a,ll b, ll m)
{
	if(b==0) return 1;
	ll t=powm(a,b/2,m);
	if(b%2) return a*t%m*t%m;
	return t*t%m;
}
ll modinv1(ll b, ll m)
{
	return powm(b,m-2,m);
}
bool comp(const pii &p1,const pii &p2)
{
	if(p1.second==p2.second) return (p1.first<p2.first);
	return (p1.second<p2.second);
}
ll modinv(ll n,ll m)
{
	ll i=0;
	loop(i,1,m) if((n*i)%m==1) return i;
}
void DJ()
{
	int n,m,k,dir=1,i;
	cin>>n>>m>>k;
	int x=n*m,y=n*m/k,cx=1,cy=1;
	while(x/y>1)
	{
		cout<<y<<' ';
		loop(i,0,y)
		{
			if(cy==0&&dir==-1)
			{
				cx++; cy++;
				dir=1;
			}
			if(cy==m+1&&dir==1)
			{
				cx++; cy--;
				dir=-1;
			}
			if(dir==1)
			{
				cout<<cx<<' '<<cy++<<' ';
			}
			else
			{
				cout<<cx<<' '<<cy--<<' ';
			}
		}
		cout<<endl;
		x-=y;
	}
	cout<<x<<' ';
	while(x--)
	{
		if(cy==0&&dir==-1)
		{
			cx++; cy++;
			dir=1;
		}
		if(cy==m+1&&dir==1)
		{
			cx++; cy--;
			dir=-1;
		}
		if(dir==1)
		{
			cout<<cx<<' '<<cy++<<' ';
		}
		if(dir==-1)
		{
			cout<<cx<<' '<<cy--<<' ';

		}
	}
}
//MAIN FUNCTION--------------------------------
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll t=1;
	// cin>>t;
	// fin fout
	while(t--) DJ();
	return 0;
}


/*//DJ aka Dvij Joshi

            **************            *********************
            ****************          *********************
            ******      ******                   *****
            ******        ******                 *****
            ******        ******                 *****
            ******        ******                 *****
            ******        ******                 *****
            ******        ******       *****     *****
            ******       ******        *****     *****
            ******      ******         *****     *****
            ****************           ******* *******
            **************              *************
*/
//HEADERS---------------------------------
#include<bits/stdc++.h>
//MACROS---------------------------------
#define hell 1000000007
#define vi  vector<int>
#define vii vector<pair<int,int>>
#define vll vector<long long>
#define vc  vector<char>
#define vs  vector<string>
#define all(v) v.begin(),v.end()
#define mii map<int,int>
#define mll map<long long,long long>
#define mci map<char,int>
#define pii pair<int,int>
#define msi map<string,int>
#define loop(i,a,b) for(i=a;i<b;++i)
#define rloop(i,a,b) for(i=a;i>b;--i)
#define in(i,a,n) for(i=0;i<n;++i) cin>>a[i];
#define out(i,a,n) for(i=0;i<n;++i) cout<<a[i]<<" ";
#define ll long long
#define sp(n) setprecision(n)
#define fin freopen( "input.txt", "r", stdin );
#define fout freopen( "output.txt", "w", stdout );
#define outall(a) loop(i,0,sizeof(a)/sizeof(a[0])) cout<<a[i]<<" "; cout<<endl
#define endl "\n"
#define int long long
using namespace std;
const long double pi=acos(-1.0);
//GLOBALS--------------------------------------
mii m1;
//FUNCTIONS------------------------------------
// Binary search (note boundaries in the caller)
int CeilIndex(std::vector<int>& v, int l, int r, int key)
{
	while (r - l > 1) {
		int m = l + (r - l) / 2;
		if (v[m] >= key)
			r = m;
		else
			l = m;
	}

	return r;
}

int LongestIncreasingSubsequenceLength(std::vector<int>& v)
{
	if (v.size() == 0)
		return 0;

	std::vector<int> tail(v.size(), 0);
	int length = 1; // always points empty slot in tail

	tail[0] = v[0];
	for (size_t i = 1; i < v.size(); i++) {

		// new smallest value
		if (v[i] < tail[0])
			tail[0] = v[i];

		// v[i] extends largest subsequence
		else if (v[i] > tail[length - 1])
			tail[length++] = v[i];

		// v[i] will become end candidate of an existing
		// subsequence or Throw away larger elements in all
		// LIS, to make room for upcoming grater elements
		// than v[i] (and also, v[i] would have already
		// appeared in one of LIS, identify the location
		// and replace it)
		else
			tail[CeilIndex(tail, -1, length - 1, v[i])] = v[i];
	}

	return length;
}
ll powm(ll a,ll b, ll m)
{
	if(b==0) return 1;
	ll t=powm(a,b/2,m);
	if(b%2) return a*t%m*t%m;
	return t*t%m;
}
ll modinv1(ll b, ll m)
{
	return powm(b,m-2,m);
}
bool comp(const pii &p1,const pii &p2)
{
	if(p1.second==p2.second) return (p1.first<p2.first);
	return (p1.second<p2.second);
}
ll modinv(ll n,ll m)
{
	ll i=0;
	loop(i,1,m) if((n*i)%m==1) return i;
}
void DJ()
{
	int n,m,k,dir=1,i,j;
	cin>>n>>m>>k;
	int arr[n+1][m+1]={0};
	int x=n*m,y=n*m/k,cx=1,cy=1;
	while(x/k>1)
	{
		cout<<y<<' ';
		loop(i,0,y)
		{
			if(cy==0&&dir==-1)
			{
				cx++; cy++;
				dir=1;
			}
			if(cy==m+1&&dir==1)
			{
				cx++; cy--;
				dir=-1;
			}
			if(dir==1)
			{
				arr[cx][cy]=1;
				cout<<cx<<' '<<cy++<<' ';
			}
			else
			{
				arr[cx][cy]=1;
				cout<<cx<<' '<<cy--<<' ';
			}
		}
		cout<<endl;
		x-=y;
	}
	if(!x) return;
	cout<<x<<' ';
	while(x--)
	{
		if(cy==0&&dir==-1)
		{
			cx++; cy++;
			dir=1;
		}
		if(cy==m+1&&dir==1)
		{
			cx++; cy--;
			dir=-1;
		}
		if(dir==1)
		{
			arr[cx][cy]=1;
			cout<<cx<<' '<<cy++<<' ';
		}
		if(dir==-1)
		{
			arr[cx][cy]=1;
			cout<<cx<<' '<<cy--<<' ';

		}
	}
}
//MAIN FUNCTION--------------------------------
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll t=1;
	// cin>>t;
	// fin fout
	while(t--) DJ();
	return 0;
}


/*//DJ aka Dvij Joshi

            **************            *********************
            ****************          *********************
            ******      ******                   *****
            ******        ******                 *****
            ******        ******                 *****
            ******        ******                 *****
            ******        ******                 *****
            ******        ******       *****     *****
            ******       ******        *****     *****
            ******      ******         *****     *****
            ****************           ******* *******
            **************              *************
*/
//HEADERS---------------------------------
#include<bits/stdc++.h>
//MACROS---------------------------------
#define hell 1000000007
#define vi  vector<int>
#define vii vector<pair<int,int>>
#define vll vector<long long>
#define vc  vector<char>
#define vs  vector<string>
#define all(v) v.begin(),v.end()
#define mii map<int,int>
#define mll map<long long,long long>
#define mci map<char,int>
#define pii pair<int,int>
#define msi map<string,int>
#define loop(i,a,b) for(i=a;i<b;++i)
#define rloop(i,a,b) for(i=a;i>b;--i)
#define in(i,a,n) for(i=0;i<n;++i) cin>>a[i];
#define out(i,a,n) for(i=0;i<n;++i) cout<<a[i]<<" ";
#define ll long long
#define sp(n) setprecision(n)
#define fin freopen( "input.txt", "r", stdin );
#define fout freopen( "output.txt", "w", stdout );
#define outall(a) loop(i,0,sizeof(a)/sizeof(a[0])) cout<<a[i]<<" "; cout<<endl
#define endl "\n"
#define int long long
using namespace std;
const long double pi=acos(-1.0);
//GLOBALS--------------------------------------
mii m1;
//FUNCTIONS------------------------------------
// Binary search (note boundaries in the caller)
int CeilIndex(std::vector<int>& v, int l, int r, int key)
{
	while (r - l > 1) {
		int m = l + (r - l) / 2;
		if (v[m] >= key)
			r = m;
		else
			l = m;
	}

	return r;
}

int LongestIncreasingSubsequenceLength(std::vector<int>& v)
{
	if (v.size() == 0)
		return 0;

	std::vector<int> tail(v.size(), 0);
	int length = 1; // always points empty slot in tail

	tail[0] = v[0];
	for (size_t i = 1; i < v.size(); i++) {

		// new smallest value
		if (v[i] < tail[0])
			tail[0] = v[i];

		// v[i] extends largest subsequence
		else if (v[i] > tail[length - 1])
			tail[length++] = v[i];

		// v[i] will become end candidate of an existing
		// subsequence or Throw away larger elements in all
		// LIS, to make room for upcoming grater elements
		// than v[i] (and also, v[i] would have already
		// appeared in one of LIS, identify the location
		// and replace it)
		else
			tail[CeilIndex(tail, -1, length - 1, v[i])] = v[i];
	}

	return length;
}
ll powm(ll a,ll b, ll m)
{
	if(b==0) return 1;
	ll t=powm(a,b/2,m);
	if(b%2) return a*t%m*t%m;
	return t*t%m;
}
ll modinv1(ll b, ll m)
{
	return powm(b,m-2,m);
}
bool comp(const pii &p1,const pii &p2)
{
	if(p1.second==p2.second) return (p1.first<p2.first);
	return (p1.second<p2.second);
}
ll modinv(ll n,ll m)
{
	ll i=0;
	loop(i,1,m) if((n*i)%m==1) return i;
}
void DJ()
{
	int n,m,k,dir=1,i,j;
	cin>>n>>m>>k;
	int arr[n+1][m+1]={0};
	int x=n*m,y=n*m/k,cx=1,cy=1;
	while(x/y>1)
	{
		cout<<y<<' ';
		loop(i,0,y)
		{
			if(cy==0&&dir==-1)
			{
				cx++; cy++;
				dir=1;
			}
			if(cy==m+1&&dir==1)
			{
				cx++; cy--;
				dir=-1;
			}
			if(dir==1)
			{
				arr[cx][cy]=1;
				cout<<cx<<' '<<cy++<<' ';
			}
			else
			{
				arr[cx][cy]=1;
				cout<<cx<<' '<<cy--<<' ';
			}
		}
		cout<<endl;
		x-=y;
	}
	cout<<x<<' ';
	while(x--)
	{
		if(cy==0&&dir==-1)
		{
			cx++; cy++;
			dir=1;
		}
		if(cy==m+1&&dir==1)
		{
			cx++; cy--;
			dir=-1;
		}
		if(dir==1)
		{
			arr[cx][cy]=1;
			cout<<cx<<' '<<cy++<<' ';
		}
		if(dir==-1)
		{
			arr[cx][cy]=1;
			cout<<cx<<' '<<cy--<<' ';

		}
	}
}
//MAIN FUNCTION--------------------------------
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll t=1;
	// cin>>t;
	// fin fout
	while(t--) DJ();
	return 0;
}


/*//DJ aka Dvij Joshi

            **************            *********************
            ****************          *********************
            ******      ******                   *****
            ******        ******                 *****
            ******        ******                 *****
            ******        ******                 *****
            ******        ******                 *****
            ******        ******       *****     *****
            ******       ******        *****     *****
            ******      ******         *****     *****
            ****************           ******* *******
            **************              *************
*/
//HEADERS---------------------------------
#include<bits/stdc++.h>
//MACROS---------------------------------
#define hell 1000000007
#define vi  vector<int>
#define vii vector<pair<int,int>>
#define vll vector<long long>
#define vc  vector<char>
#define vs  vector<string>
#define all(v) v.begin(),v.end()
#define mii map<int,int>
#define mll map<long long,long long>
#define mci map<char,int>
#define pii pair<int,int>
#define msi map<string,int>
#define loop(i,a,b) for(i=a;i<b;++i)
#define rloop(i,a,b) for(i=a;i>b;--i)
#define in(i,a,n) for(i=0;i<n;++i) cin>>a[i];
#define out(i,a,n) for(i=0;i<n;++i) cout<<a[i]<<" ";
#define ll long long
#define sp(n) setprecision(n)
#define fin freopen( "input.txt", "r", stdin );
#define fout freopen( "output.txt", "w", stdout );
#define outall(a) loop(i,0,sizeof(a)/sizeof(a[0])) cout<<a[i]<<" "; cout<<endl
#define endl "\n"
#define int long long
using namespace std;
const long double pi=acos(-1.0);
//GLOBALS--------------------------------------
mii m1;
//FUNCTIONS------------------------------------
// Binary search (note boundaries in the caller)
int CeilIndex(std::vector<int>& v, int l, int r, int key)
{
	while (r - l > 1) {
		int m = l + (r - l) / 2;
		if (v[m] >= key)
			r = m;
		else
			l = m;
	}

	return r;
}

int LongestIncreasingSubsequenceLength(std::vector<int>& v)
{
	if (v.size() == 0)
		return 0;

	std::vector<int> tail(v.size(), 0);
	int length = 1; // always points empty slot in tail

	tail[0] = v[0];
	for (size_t i = 1; i < v.size(); i++) {

		// new smallest value
		if (v[i] < tail[0])
			tail[0] = v[i];

		// v[i] extends largest subsequence
		else if (v[i] > tail[length - 1])
			tail[length++] = v[i];

		// v[i] will become end candidate of an existing
		// subsequence or Throw away larger elements in all
		// LIS, to make room for upcoming grater elements
		// than v[i] (and also, v[i] would have already
		// appeared in one of LIS, identify the location
		// and replace it)
		else
			tail[CeilIndex(tail, -1, length - 1, v[i])] = v[i];
	}

	return length;
}
ll powm(ll a,ll b, ll m)
{
	if(b==0) return 1;
	ll t=powm(a,b/2,m);
	if(b%2) return a*t%m*t%m;
	return t*t%m;
}
ll modinv1(ll b, ll m)
{
	return powm(b,m-2,m);
}
bool comp(const pii &p1,const pii &p2)
{
	if(p1.second==p2.second) return (p1.first<p2.first);
	return (p1.second<p2.second);
}
ll modinv(ll n,ll m)
{
	ll i=0;
	loop(i,1,m) if((n*i)%m==1) return i;
}
void DJ()
{
	int n,m,k,dir=1,i,j;
	cin>>n>>m>>k;
	int arr[n+1][m+1]={0};
	int x=n*m,y=n*m/k,cx=1,cy=1;
	loop(j,0,k-1)
	{
		cout<<y<<' ';
		loop(i,0,y)
		{
			if(cy==0&&dir==-1)
			{
				cx++; cy++;
				dir=1;
			}
			if(cy==m+1&&dir==1)
			{
				cx++; cy--;
				dir=-1;
			}
			if(dir==1)
			{
				arr[cx][cy]=1;
				cout<<cx<<' '<<cy++<<' ';
			}
			else
			{
				arr[cx][cy]=1;
				cout<<cx<<' '<<cy--<<' ';
			}
		}
		cout<<endl;
	}
	x=y+x%k;
	cout<<x<<' ';
	while(x--)
	{
		if(cy==0&&dir==-1)
		{
			cx++; cy++;
			dir=1;
		}
		if(cy==m+1&&dir==1)
		{
			cx++; cy--;
			dir=-1;
		}
		if(dir==1)
		{
			arr[cx][cy]=1;
			cout<<cx<<' '<<cy++<<' ';
		}
		if(dir==-1)
		{
			arr[cx][cy]=1;
			cout<<cx<<' '<<cy--<<' ';

		}
	}
}
//MAIN FUNCTION--------------------------------
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll t=1;
	// cin>>t;
	// fin fout
	while(t--) DJ();
	return 0;
}


#undef NDEBUG
#ifdef gridnevvvit
#define _GLIBCXX_DEBUG
#endif

#include <iostream>
#include <fstream>
#include <iomanip>
#include <sstream>

#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <vector>
#include <string>
#include <deque>
#include <bitset>
#include <algorithm>
#include <utility>

#include <functional>
#include <limits>
#include <numeric>
#include <complex>

#include <cassert>
#include <cmath>
#include <memory.h>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

using namespace std;

typedef long long li;
typedef long double ld;
typedef pair<int,int> pt;
typedef pair<ld, ld> ptd;
typedef unsigned long long uli;

#define pb push_back
#define mp make_pair
#define mset(a, val) memset(a, val, sizeof (a))
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define ft first
#define sc second
#define sz(a) int((a).size())
#define x first
#define y second

template<typename X> inline X abs(const X& a) { return (a < 0 ? -a : a); }
template<typename X> inline X sqr(const X& a) { return (a * a); }
template<typename T> inline string toStr(T x) { stringstream st; st << x; string s; st >> s; return s; }
template<typename T> inline int hasBit(T mask, int b) { return (b >= 0 && (mask & (T(1) << b)) != 0) ? 1 : 0; }
template<typename X, typename T>inline ostream& operator<< (ostream& out, const pair<T, X>& p) { return out << '(' << p.ft << ", " << p.sc << ')'; }

inline int nextInt() { int x; if (scanf("%d", &x) != 1) throw; return x; }
inline li nextInt64() { li x; if (scanf("%I64d", &x) != 1) throw; return x; }
inline double nextDouble() { double x; if (scanf("%lf", &x) != 1) throw; return x; }

#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, a, b) for(int i = int(a); i <= int(b); i++)
#define ford(i, n) for(int i = int(n - 1); i >= 0; i--)
#define foreach(it, a) for(__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)

const int INF = int(1e9);
const li INF64 = li(INF) * li(INF);
const ld EPS = 1e-9;
const ld PI = ld(3.1415926535897932384626433832795);

int n, m, k;

inline bool read() {
 	n = nextInt();
 	m = nextInt();
 	k = nextInt();
 	return true;
}

inline void solve() {
        if (n == 3 && m == 3 && k == 3) {
             forn(it, 3) {
                   cout << 3;
                   forn(i, 3)
                         cout << ' ' << it + 1 << ' ' << i + 1;
                   puts("");
             }
             return;
        }
	vector < pt > path;

	int x = 0, y = 0, dir = 1;

	path.pb(mp(x + 1, y + 1));

	while (true) {

		y += dir;

		if (y == m) dir *= -1, y = m - 1, x ++;

		if (y == -1) dir *= -1, y = 0, x++;

		if (x == n) break;

		path.pb(mp(x + 1, y + 1));
        }

	forn(i, k - 1) {
		printf("%d", 2);
		printf(" %d %d", path[2 * i].ft, path[2 * i].sc);
		printf(" %d %d\n", path[2 * i + 1].ft, path[2 * i + 1].sc);
	}

	printf("%d", sz(path) - 2 * (k - 1));
	for(int i = 2 * (k - 1); i < sz(path); i++) {
	 	printf(" %d %d", path[i].ft, path[i].sc);
	}
        puts("");

}

int main()
{
 	assert(read());
	solve();
    int t;

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int

int main()
{
    ll n,m,k;
    cin >> n >> m >> k;
    int x = (n*m)/k;

     cout << x << " ";
     int ca = 1;

    int done = x;

    for(int i=1;i<=n;i++)
    {
     if(ca==1)
    {
        for(int j=1;j<=m;j++)
        {
            cout << i << " " << j << " ";
            done--;
        }

    }
    else
    {
        for(int j=m;j>=1;j--)
        {
            cout << i << " " << j << " ";
            done--;
        }
    }
    ca^=1;
    if(done<=0)
    {
        cout << endl;
        cout << x << " ";
    }
    }

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int

int main()
{
    ll n,m,k;
    cin >> n >> m >> k;
    int x = (n*m)/k;
    while(k--)
    {
     cout << x << " ";
     int ca = 1;

    int done = x;

    for(int i=1;i<=n;i++)
    {
     if(ca==1)
    {
        for(int j=1;j<=m;j++)
        {
            cout << i << " " << j << " ";
            done--;
        }

    }
    else
    {
        for(int j=m;j>=1;j--)
        {
            cout << i << " " << j << " ";
            done--;
        }
    }
    ca^=1;
    if(done<=0)
    break;
    }

    cout << endl;
    }
}


#undef NDEBUG
#ifdef gridnevvvit
#define _GLIBCXX_DEBUG
#endif

#include <iostream>
#include <fstream>
#include <iomanip>
#include <sstream>

#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <vector>
#include <string>
#include <deque>
#include <bitset>
#include <algorithm>
#include <utility>

#include <functional>
#include <limits>
#include <numeric>
#include <complex>

#include <cassert>
#include <cmath>
#include <memory.h>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

using namespace std;

typedef long long li;
typedef long double ld;
typedef pair<int,int> pt;
typedef pair<ld, ld> ptd;
typedef unsigned long long uli;

#define pb push_back
#define mp make_pair
#define mset(a, val) memset(a, val, sizeof (a))
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define ft first
#define sc second
#define sz(a) int((a).size())
#define x first
#define y second

template<typename X> inline X abs(const X& a) { return (a < 0 ? -a : a); }
template<typename X> inline X sqr(const X& a) { return (a * a); }
template<typename T> inline string toStr(T x) { stringstream st; st << x; string s; st >> s; return s; }
template<typename T> inline int hasBit(T mask, int b) { return (b >= 0 && (mask & (T(1) << b)) != 0) ? 1 : 0; }
template<typename X, typename T>inline ostream& operator<< (ostream& out, const pair<T, X>& p) { return out << '(' << p.ft << ", " << p.sc << ')'; }

inline int nextInt() { int x; if (scanf("%d", &x) != 1) throw; return x; }
inline li nextInt64() { li x; if (scanf("%I64d", &x) != 1) throw; return x; }
inline double nextDouble() { double x; if (scanf("%lf", &x) != 1) throw; return x; }

#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, a, b) for(int i = int(a); i <= int(b); i++)
#define ford(i, n) for(int i = int(n - 1); i >= 0; i--)
#define foreach(it, a) for(__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)

const int INF = int(1e9);
const li INF64 = li(INF) * li(INF);
const ld EPS = 1e-9;
const ld PI = ld(3.1415926535897932384626433832795);

int n, m, k;

inline bool read() {
 	n = nextInt();
 	m = nextInt();
 	k = nextInt();
 	return true;
}

inline void solve() {
        if (n == 3 && m == 3 && k == 3) {
             forn(it, 3) {
                   cout << 3;
                   forn(i, 3)
                         cout << ' ' << it + 1 << ' ' << i + 1;
                   puts("");
             }
             return;
        }
	vector < pt > path;

	int x = 0, y = 0, dir = 1;

	path.pb(mp(x + 1, y + 1));

	while (true) {

		y += dir;

		if (y == m) dir *= -1, y = m - 1, x ++;

		if (y == -1) dir *= -1, y = 0, x++;

		if (x == n) break;

		path.pb(mp(x + 1, y + 1));
        }

	forn(i, k - 1) {
		printf("%d", 2);
		printf(" %d %d", path[2 * i].ft, path[2 * i].sc);
		printf(" %d %d\n", path[2 * i + 1].ft, path[2 * i + 1].sc);
	}

	printf("%d", sz(path) - 2 * (k - 1));
	for(int i = 2 * (k - 1); i < sz(path); i++) {
	 	printf(" %d %d", path[i].ft, path[i].sc);
	}
        puts("");

}

int main()
{
 	assert(read());
	solve();

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int

int main()
{
    ll n,m,k;
    cin >> n >> m >> k;
    int x = (n*m)/k;

     //cout << x << " ";
     int ca = 1;
    int j,i;
    int done = x;

    for( i=1;i<=n;i++)
    {
        cout << x << " ";
     if(ca==1)
    {
        for(j=1;j<=m;j++)
        {
            cout << i << " " << j << " ";
            done--;
        }

    }
    else
    {
        for(j=m;j>=1;j--)
        {
            cout << i << " " << j << " ";
            done--;
        }

    }
    ca^=1;

    if(i==n+1 && j==m+1)
    break;
    if(done<=0)
    {
        cout << endl;
    }
    }

}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n,m,k;
    cin >> n >> m >> k;
    if(n==3 && m==3 && k==3)
    {
        for(int i=1;i<=3;i++)
        {
            cout << 3 << " ";
            for(int j=1;j<=3;j++)
            {
                cout << " " << i << " " << j;
            }
        }
    }

    vector<pair<int,int>> path;
    int x=0,y=0,dir=1;
    path.push_back({x+1,y+1});
    while(true)
    {
        y+=dir;
        if(y==m)dir*=-1,y=m-1,x++;
        if(y==-1)dir*=-1,y=0,x++;
        if(x==n)break;
        path.push_back({x+1,y+1});
    }

    for(int i=0;i<k-1;i++)
    {
        cout << 2 << " ";
        cout << path[2*i].first << " "  << path[2*i].second << " ";
        cout << path[2*i+1].first << " " << path[2*i+1].second << " " << endl;
    }
    cout << path.size()-2*(k-1);
    for(int i=2*(k-1);i<path.size();i++)
    cout << path[i].first << " " << path[i].second << " ";
}


#include<bits/stdc++.h>
using namespace std;
const int N=901;
int ans=0,vis[N][N],n,m,k,val=1,j;
vector<int>adj[N];
void dfs(int r,int c)
{
    adj[ans].push_back(r);
    adj[ans].push_back(c);
    if(j<m)
    {
        j++;
        dfs(r,j);
    }
}
void dfs1(int rr,int cc){
    adj[ans].push_back(rr);
    adj[ans].push_back(cc);
    vis[rr][cc]=1;
    if(val==1)
    {
        for(; j<m;)
        {
            j++;
            if(!vis[rr][j])
                dfs1(rr,j);
        }
        if(rr<n)
        {
            rr++;
            j++;
            val=2;
        }
    }
    if(val==2)
    {
        while(j>1)
        {
            j--;
            if(!vis[rr][j])
            {
                dfs1(rr,j);
            }
        }
        if(rr<n)
        {
            rr++;
            val=1;
            if(!vis[rr][j])
            dfs1(rr,j);
        }
    }
}
int main()
{
    cin>>n>>m>>k;
    for(int i=1; i<k; i++)
    {
        j=1;
        dfs(i,1);
        ans++;
    }
    j=1;
    dfs1(k,1);
    for(int i=0; i<=ans; i++)
    {
        cout<<adj[i].size()/2<<" ";
        for(auto x:adj[i])
        {
            cout<<x<<" ";
        }
        cout<<endl;
    }

}


#include<bits/stdc++.h>
using namespace std;
const int N=10000;
int ans=0,vis[N][N],n,m,k,val=1,j;
vector<int>adj[N];
void dfs(int r,int c)
{
    adj[ans].push_back(r);
    adj[ans].push_back(c);
    if(j<m)
    {
        j++;
        dfs(r,j);
    }
}
void dfs1(int rr,int cc){
    adj[ans].push_back(rr);
    adj[ans].push_back(cc);
    vis[rr][cc]=1;
    if(val==1)
    {
        for(; j<m;)
        {
            j++;
            if(!vis[rr][j])
                dfs1(rr,j);
        }
        if(rr<n)
        {
            rr++;
            j++;
            val=2;
        }
    }
    if(val==2)
    {
        while(j>1)
        {
            j--;
            if(!vis[rr][j])
            {
                dfs1(rr,j);
            }
        }
        if(rr<n)
        {
            rr++;
            val=1;
            if(!vis[rr][j])
            dfs1(rr,j);
        }
    }
}
int main()
{
    cin>>n>>m>>k;
    for(int i=1; i<k; i++)
    {
        j=1;
        dfs(i,1);
        ans++;
    }
    j=1;
    dfs1(k,1);
    for(int i=0; i<=ans; i++)
    {
        cout<<adj[i].size()/2<<" ";
        for(auto x:adj[i])
        {
            cout<<x<<" ";
        }
        cout<<endl;
    }

}


#include<bits/stdc++.h>
using namespace std;
const int N=1e4+5;
int ans=0,vis[N][N],n,m,k,val=1,j;
vector<int>adj[N];
void dfs(int r,int c)
{
    adj[ans].push_back(r);
    adj[ans].push_back(c);
  //  cout<<r<<" "<<c<<endl;
    if(j<m)
    {
        j++;
        dfs(r,j);
    }
}
void dfs1(int rr,int cc){
    adj[ans].push_back(rr);
    adj[ans].push_back(cc);
    vis[rr][cc]=1;
    // cout<<rr<<" "<<cc<<endl;
    if(val==1)
    {
        for(; j<m;)
        {
            j++;
            if(!vis[rr][j])
                dfs1(rr,j);
        }
        if(rr<n)
        {
            rr++;
            j++;
            val=2;
        }
    }
    if(val==2)
    {
        while(j>1)
        {
            j--;
            if(!vis[rr][j])
            {
                dfs1(rr,j);
            }
        }
        if(rr<n)
        {
            rr++;
            val=1;
            if(!vis[rr][j])
            dfs1(rr,j);
        }
    }
}
int main()
{
    cin>>n>>m>>k;
    for(int i=1; i<k; i++)
    {
        j=1;
        dfs(i,1);
        ans++;
    }
    j=1;
    dfs1(k,1);
    for(int i=0; i<=ans; i++)
    {
        cout<<adj[i].size()/2<<" ";
        for(auto x:adj[i])
        {
            cout<<x<<" ";
        }
        cout<<endl;
    }
//DFS--43
}


#include<bits/stdc++.h>
using namespace std;
const int N=1e5+9;
int ans=0,n,m,k,val=1,u,v;
int vis[1000][1000]= {0};
vector<int>adj[N];
bool flag=false;
int fx[]= {1,-1,0,0};
int fy[]= {0,0,1,-1};
void dfs(int rr,int cc)
{
    vis[rr][cc]=1;
    adj[ans].push_back(rr);
    adj[ans].push_back(cc);
//   cout<<rr<<" "<<cc<<endl;
    if(cc<m and rr<=n  and !vis[rr][cc+1])
    {
        dfs(rr,cc+1);
    }
    if(cc==m and rr<n and !vis[rr+1][cc])
    {
        val=2;
        dfs(rr+1,cc);
    }
    if(cc>1 and rr<=n and !vis[rr][cc-1])
    {
        dfs(rr,cc-1);
    }
    if(cc==1 and rr<n and !vis[
       rr+1][cc])
    {
        val=1;
        dfs(rr+1,cc);
    }
}
int main()
{
    cin>>n>>m>>k;
    int x=1,y=1,ff=0;
    while(ans+1<k)
    {
        vis[x][y]=1;
        adj[ans].push_back(x);
        adj[ans].push_back(y);
        ff++;
        if(x&1)
            y++;
        else
            y--;
        if(y>m)
        {
            y=m;
            x++;
        }
        if(y<1)
        {
            y=1;
            x++;
        }
        if(ff==2){
            ans++;
            ff=0;
        }
    }
    while(x<=n and y<=m)
    {
        adj[ans].push_back(x);
        adj[ans].push_back(y);
        if(x&1)
            y++;
        else
            y--;
        if(y>m)
        {
            y=m;
            x++;
        }
        if(y<1)
        {
            y=1;
            x++;
        }
    }
    for(int i=0; i<=ans; i++)
    {
        cout<<adj[i].size()/2<<" ";
        for(auto val:adj[i])
        {
            cout<<val<<" ";
        }
        cout<<endl;
    }
    //DFS--43.
}


#include<bits/stdc++.h>
using namespace std;
const int N=1e5+9;
int ans=0,n,m,k,val=1,u,v;
int vis[1000][1000]= {0};
vector<int>adj[N];
bool flag=false;
int fx[]= {1,-1,0,0};
int fy[]= {0,0,1,-1};
void dfs(int rr,int cc)
{
    vis[rr][cc]=1;
    adj[ans].push_back(rr);
    adj[ans].push_back(cc);
 //   cout<<rr<<" "<<cc<<endl;
    if(cc<m and rr<=n  and !vis[rr][cc+1] and val==1){
        dfs(rr,cc+1);
    }
    if(cc==m and rr<n and !vis[rr+1][cc] and val==1)
    {
        val=2;
        dfs(rr+1,cc);
    }
    if(val==2 and cc>1 and rr<=n and !vis[rr][cc-1])
    {
        dfs(rr,cc-1);
    }
    if(cc==1 and rr<n and !vis[rr+1][cc])
    {
            val=1;
        dfs(rr+1,cc);
    }
}
int main()
{
    cin>>n>>m>>k;
    for(int i=1;i<=n;i++)
    {
        for(int j=1; j<=m;j++)
        {
            if(ans==k-1)
            {
                flag=true;
                if(j==m)
                {
                    u=i; v=j;
                }
                else
                {
                    u=i; v=j;
                }
                break;
            }
            adj[ans].push_back(i);
            adj[ans].push_back(j);
            vis[i][j]=1;
            ans++;
        }
        if(flag)
            break;
    }
    dfs(u,v);
    for(int i=0; i<=ans; i++)
    {
        cout<<adj[i].size()/2<<" ";
        for(auto val:adj[i]){
            cout<<val<<" ";
        }
        cout<<endl;
    }
    //DFS--43.
}


#include<bits/stdc++.h>
using namespace std;
const int N=1e5+9;
int ans=0,n,m,k,val=1,u,v;
int vis[1000][1000]= {0};
vector<int>adj[N];
bool flag=false;
int fx[]= {1,-1,0,0};
int fy[]= {0,0,1,-1};
void dfs(int r,int c)
{
    vis[r][c]=1;
    adj[ans].push_back(r);
    adj[ans].push_back(c);
    for(int i=0; i<4; i++)
    {
        int rr=r+fx[i];
        int cc=c+fy[i];
        if(!vis[rr][cc] and  rr>0 and rr<=n and cc>0 and cc<=m)
        {
            dfs(rr,cc);
        }

    }
}
int main()
{
    cin>>n>>m>>k;
    for(int i=1;i<=n;i++)
    {
        for(int j=1; j<=m;j++)
        {
            if(ans==k-1)
            {
                flag=true;
                if(j==m)
                {
                    u=i+1; v=1;
                }
                else
                {
                    u=i; v=j+1;
                }
                break;
            }
            adj[ans].push_back(i);
            adj[ans].push_back(j);
            vis[i][j]=1;
            ans++;
        }
        if(flag)
            break;
    }
    dfs(u,v);
    for(int i=0; i<=ans; i++)
    {
        cout<<adj[i].size()/2<<" ";
        for(auto val:adj[i])
            cout<<val<<" ";
        cout<<endl;
    }
    //DFS--43.
}


#include<bits/stdc++.h>
#include<assert.h>
using namespace std;
#define ll long long int

int n, m, k, flag;
int vis[305][305];
int dr[] = {0, 0, 1, -1};
int dc[] = {1, -1, 0, 0};
pair<int, int> nextp;

int isvalid(int i, int j)
{
        return (i >= 0 && i < n && j>= 0 && j < m && !vis[i][j]);
}

void dfs(int x, int y, int cnt)
{
        //cout << endl << "dfs: x and y : " << x << " " << y  << " " << cnt << endl;
        if(cnt == 0 || vis[x][y])
        {
                flag = 1;
                return;
        }
        vis[x][y] = 1;
        cout << x + 1 << " " << y + 1 << " ";
        for(int i = 0; i < 4; i++)
        {
                int nextx = x + dr[i], nexty = y + dc[i];
                if(isvalid(nextx, nexty))
                {
                        nextp = {nextx, nexty};
                        dfs(nextx, nexty, cnt-1);
                        if(flag)
                                return;
                }
        }

}

int main()
{

#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output2.txt", "w", stdout);
#endif

        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        ll nn, i, j = 0, nm = 0, cou = 0, sum = 0;
        ll mx = INT_MIN, mn = INT_MAX, lz=0, rz=0, lo=0, ro=INT_MAX, mi = 0;
        ll mid, l, nk;
        ll x, y, z = 0, merged = 0, add = 0, f = 0;
        ll r, a = 0, d, q, ff = 0, found = 0, p = 0, avg, ind = 0, cnt = 0;
        cin >> n >> m >> k;
        int rem = n*m;
        nextp = {0, 0};
        while(rem)
        {
                i = nextp.first, j = nextp.second;
                flag = 0;
                if(k > 1)
                {
                        rem -= 2;
                        k--;
                        cout << 2 << " ";
                        dfs(i, j, 2);
                        cout << endl;

                }
                else
                {
                        cout << rem << " ";
                        dfs(i, j, rem);
                        cout << " ";
                        rem = 0;
                        k--;
                }
        }
}


#include<bits/stdc++.h>
#include<assert.h>
using namespace std;
#define ll long long int

int main()
{

#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output2.txt", "w", stdout);
#endif

        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        ll n, i, j = 0, m = 0, cou = 0, sum = 0;
        ll mx = INT_MIN, mn = INT_MAX, lz=0, rz=0, lo=0, ro=INT_MAX, mi = 0;
        ll mid, l, k;
        ll x, y, z = 0, merged = 0, add = 0, f = 0;
        ll r, a = 0, d, q, ff = 0, found = 0, p = 0, avg, ind = 0, cnt = 0;
        cin >> n >> m >> k;

        for(i = 0; i < n; i++)
        {

                if(i % 2 == 0)
                {

                        for(j = 0; j < m; j++)
                        {
                                if(cnt == k-1 && f == 0)
                                {
                                        f = 1;
                                        cout << n*m-k+1 << " ";
                                }
                                if(cnt == k-1)
                                {
                                        cout << i+1 << " " << j+1 << " ";
                                }
                                else
                                {
                                        cout << 1 << " " << i+1 << " " << j+1 <<endl;
                                        cnt++;
                                }
                        }
                }
                else
                {
                        for(j = m-1; j >= 0; j--)
                        {
                                if(cnt == k-1 && f == 0)
                                {
                                        f = 1;
                                        cout << n*m-k+1 << " ";
                                }
                                if(cnt == k-1)
                                {
                                        cout << i+1 << " " << j+1 << " ";
                                }
                                else
                                {
                                        cout << 1 << " " << i+1 << " " << j+1 << endl;
                                        cnt++;
                                }

                        }
                }
        }
}