#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int,int> pint;

#define DE 1
#define FI first
#define SE second
#define PB push_back
#define MP make_pair
#define ALL(s) (s).begin(),(s).end()
#define REP(i,n) for (int i = 0; i < (int)(n); ++i)
#define EACH(i,s) for (typeof((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl

template<class T1, class T2> ostream& operator<<(ostream &s, pair<T1,T2> P){return s<<'<'<<P.first<<", "<<P.second<<'>';}
template<class T> ostream& operator<<(ostream &s, vector<T> P) {s<<"{ ";for(int i=0;i<P.size();++i){if(i>0)s<<", ";s<<P[i];}return s<<" }"<<endl;}
template<class T1, class T2> ostream& operator<<(ostream &s, map<T1,T2> P) {s<<"{ ";for(typeof(P.begin()) it=P.begin();it!=P.end();++it){if(it!=P.begin())s<<", ";s<<'<'<<it->first<<"->"<<it->second<<'>';}return s<<" }"<<endl;}



int l[15], r[15], s[15];

int main() {
    //freopen( "/Users/macuser/Documents/Programming/Contest/input.in", "r", stdin );
    
    int n, x, m;
    cin >> n >> x >> m;
    memset(l, 0, sizeof(l)); memset(r, 0, sizeof(r)); memset(s, 0, sizeof(s));
    for (int i = 0; i < m; ++i) {
        cin >> l[i] >> r[i] >> s[i];
    }
    
    int res = -1;
    int ans[10];
    
    int a[10];
    for (a[1] = 0; a[1] <= x; ++a[1]) {
        for (a[2] = 0; a[2] <= x; ++a[2]) {
            for (a[3] = 0; a[3] <= x; ++a[3]) {
                for (a[4] = 0; a[4] <= x; ++a[4]) {
                    for (a[5] = 0; a[5] <= x; ++a[5]) {
                        for (a[6] = 0; a[6] <= x; ++a[6]) {
                            bool ok = true;
                            for (int i = 0; i < m; ++i) {
                                int total = 0;
                                for (int j = l[i]; j <= r[i]; ++j) total += a[j];
                                if (total != s[i]) ok = false;
                                if (!ok) break;
                            }
                            if (!ok) continue;
                            else {
                                int sum = 0;
                                for (int i = 1; i <= n; ++i) sum += a[i];
                                
                                if (sum > res) {
                                    res = sum;
                                    for (int i = 1; i <= n; ++i) ans[i] = a[i];
                                }
                            }
                        }
                    }
                }                                   
            }           
        }              
    }
    
    if (res != -1) {
        for (int i = 1; i <= n; ++i) {
            cout << ans[i];
            if (i != n) cout << " ";
        }
        cout << endl;
    }
    else cout << -1 << endl;
    
    return 0;
}


Measured memory_bytes: 1168