#include <bits/stdc++.h>
using namespace std;
vector<long long> v;
long long x, y, z, a, b, c, sum, ans, total, t, cnt, n, m, k, p, kase;
string s1, s2;
void flip(long long start, long long last) {
  for (long long i = start; i <= last; i++) {
    if (s1[i] == '0')
      s1[i] = '1';
    else
      s1[i] = '0';
  }
  reverse(s1.begin(), s1.begin() + last + 1);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> t;
  while (t--) {
    cin >> n;
    cin >> s1 >> s2;
    k = 0;
    for (long long i = n - 1; i >= 0; i--) {
      if (s2[i] != s1[i]) {
        if (s1[0] == s2[i]) {
          flip(0, 0);
          v.push_back(0);
        }
        if (s2[i] != s1[i]) {
          flip(0, i);
          v.push_back(i);
        }
      }
    }
    cout << v.size() << " ";
    for (long long i = 0; i < v.size(); i++) cout << v[i] + 1 << " ";
    cout << endl;
    v.clear();
  }
  return 0;
}
