#include <bits/stdc++.h>
using namespace std;
// Function to calculate sums of all subsets
void subsetSums(int nums[], int n) {
// Use a set to store all subset sums (sorted and unique)
set<int> s;
s.insert(0); // Initialize with the sum of the empty subset
// Iterate over each element in the array
for (int i = 0; i < n; i++) {
vector<int> current(s.begin(), s.end()); // Copy current elements to iterate safely
for (int sum : current) {
s.insert(sum + nums[i]); // Add current element to each existing subset sum
}
}
// Print all subset sums in ascending order
for (int sum : s) {
cout << sum << " ";
}
cout << endl;
}
// Driver code
int main() {
int t;cin>>t;
while(t--){
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
subsetSums(a, n);}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgovLyBGdW5jdGlvbiB0byBjYWxjdWxhdGUgc3VtcyBvZiBhbGwgc3Vic2V0cwp2b2lkIHN1YnNldFN1bXMoaW50IG51bXNbXSwgaW50IG4pIHsKICAgIC8vIFVzZSBhIHNldCB0byBzdG9yZSBhbGwgc3Vic2V0IHN1bXMgKHNvcnRlZCBhbmQgdW5pcXVlKQogICAgc2V0PGludD4gczsKICAgIHMuaW5zZXJ0KDApOyAvLyBJbml0aWFsaXplIHdpdGggdGhlIHN1bSBvZiB0aGUgZW1wdHkgc3Vic2V0CgogICAgLy8gSXRlcmF0ZSBvdmVyIGVhY2ggZWxlbWVudCBpbiB0aGUgYXJyYXkKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbjsgaSsrKSB7CiAgICAgICAgdmVjdG9yPGludD4gY3VycmVudChzLmJlZ2luKCksIHMuZW5kKCkpOyAvLyBDb3B5IGN1cnJlbnQgZWxlbWVudHMgdG8gaXRlcmF0ZSBzYWZlbHkKICAgICAgICBmb3IgKGludCBzdW0gOiBjdXJyZW50KSB7CiAgICAgICAgICAgIHMuaW5zZXJ0KHN1bSArIG51bXNbaV0pOyAvLyBBZGQgY3VycmVudCBlbGVtZW50IHRvIGVhY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