#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void makeEdge(int (* graph)[7], int row, int col, int w);
void makeGraph(int (* graph)[7])
{
makeEdge(graph, 1, 2, 1);
makeEdge(graph, 1, 3, 1);
makeEdge(graph, 1, 4, 1);
makeEdge(graph, 1, 6, 2);
makeEdge(graph, 2, 3, 1);
makeEdge(graph, 3, 5, 4);
makeEdge(graph, 5, 6, 3);
makeEdge(graph, 5, 5, 4);
}
void modify_weight_utils(int (* graph)[7], int node1, int node2, int weight, int n)
{
graph[node1][node2] = weight;
}
void modify_weight(int (* graph)[7], int node1, int node2, int weight, int n)
{
if (node1 >= n || node2 >= n || node1 < 1 || node2 < 1)
{
printf("-1");
return;
}
modify_weight_utils(graph, node1, node2, weight, n);
modify_weight_utils(graph, node2, node1, weight, n);
}
void makeEdge(int (* graph)[7], int row, int col, int w)
{
graph[row][col] = w;
graph[col][row] = w;
}
void print_graph(int (* graph)[7], int row, int n)
{
int flag = 1;
for (int i = 1; i < n; i++)
{
if (graph[row][i] != 0)
{
printf(" %d %d", i, graph[row][i]);
flag = 0;
}
}
printf("\n");
}
int main()
{
int graph[7][7];
int r = 7, c = 7;
int n = 7;
int n1, n2, w;
char order;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
graph[i][j] = 0;
}
}
makeGraph(graph);
while (1)
{
scanf("%c", &order);
if (order == 'a')
{
scanf("%d", &n1);
if (n1 < 1 || n1 > 6)
printf("-1");
else
print_graph(graph, n1, n);
}
else if (order == 'm')
{
scanf("%d %d %d", &n1, &n2, &w);
modify_weight(graph, n1, n2, w, n);
}
else if (order = 'q')
{
break;
}
getchar();
}
}