{"trustable":true,"sections":[{"title":"","value":{"format":"MD","content":"The people of Mohammadpur have decided to paint each of their houses red, green, or blue. They\u0027ve also decided that no two neighboring houses will be painted the same color. The neighbors of house **i** are houses **i-1** and **i+1**. The first and last houses are not neighbors.\n\nYou will be given the information of houses. Each house will contain three integers **\"R G B\"** (quotes for clarity only), where **R, G** and **B** are the costs of painting the corresponding house red, green, and blue, respectively. Return the minimal total cost required to perform the work."}},{"title":"Input","value":{"format":"MD","content":"Input starts with an integer **T (\u0026le; 100)**, denoting the number of test cases.\n\nEach case begins with a blank line and an integer **n (1 \u0026le; n \u0026le; 20)** denoting the number of houses. Each of the next **n** lines will contain 3 integers **\"R G B\"**. These integers will lie in the range **[1, 1000]**."}},{"title":"Output","value":{"format":"MD","content":"For each case of input you have to print the case number and the minimal cost."}},{"title":"Sample","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e2\n\n4\n13 23 12\n77 36 64\n44 89 76\n31 78 45\n\n3\n26 40 83\n49 60 57\n13 89 99\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003eCase 1: 137\nCase 2: 96\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}