#include <iostream>
#include <vector>
#include <climits>
using namespace std;

class FenwickTree {
private:
    vector<long long> tree;
    int size;

public:
    FenwickTree(int n) : size(n) {
        tree.resize(n + 1, 0);
    }
    void add(int idx, long long value) {
        while (idx <= size) {
            tree[idx] += value;
            idx += idx & -idx;
        }
    }
    long long sum(int idx) {
        long long result = 0;
        while (idx > 0) {
            result += tree[idx];
            idx -= idx & -idx;
        }
        return result;
    }
    void rangeAdd(int left, int right, long long value) {
        add(left, value);
        add(right + 1, -value);
    }

    long long pointQuery(int idx) {
        return sum(idx);
    }
};

long long skipUpdate(int N, int Q, vector<vector<int>>& updates) {

    FenwickTree fenwick(N);

    for (const auto& update : updates) {
        int L = update[0];
        int R = update[1];
        int X = update[2];
        fenwick.rangeAdd(L, R, X);
    }

    vector<long long> fullArray(N + 1);
    for (int i = 1; i <= N; ++i) {
        fullArray[i] = fenwick.pointQuery(i);
    }

    long long minMaxValue = LLONG_MAX;

    for (const auto& update : updates) {
        int L = update[0];
        int R = update[1];
        int X = update[2];

        fenwick.rangeAdd(L, R, -X);

        long long currentMax = LLONG_MIN;
        for (int i = 1; i <= N; ++i) {
            currentMax = max(currentMax, fenwick.pointQuery(i));
        }

        minMaxValue = min(minMaxValue, currentMax);

        fenwick.rangeAdd(L, R, X);
    }

    return minMaxValue;
}

int main() {
    int T;
    cin >> T;

    while (T--) {
        int N, Q;
        cin >> N >> Q;

        vector<vector<int>> updates(Q, vector<int>(3));
        for (int i = 0; i < Q; ++i) {
            cin >> updates[i][0] >> updates[i][1] >> updates[i][2];
        }

        cout << skipUpdate(N, Q, updates) << endl;
    }

    return 0;
}
