#include <bits/stdc++.h>
using namespace std;
void solve(long long int t) {
  long long int n;
  cin >> n;
  string a, b;
  cin >> a >> b;
  vector<long long int> v;
  for (long long int i = n - 1; i >= 0; i--) {
    if (a[i] == b[i]) continue;
    if (a[i] == '1') {
      if (a[0] == '1') {
        v.push_back(i + 1);
        string s = "";
        for (long long int j = i; j >= 0; j--) {
          if (a[j] == '1')
            s += '0';
          else
            s += '1';
        }
        for (long long int j = i + 1; j < n; j++) s += a[j];
        a = s;
      } else {
        v.push_back(1);
        if (a[0] == '1')
          a[0] = '0';
        else
          a[0] = '1';
        v.push_back(i + 1);
        string s = "";
        for (long long int j = i; j >= 0; j--) {
          if (a[j] == '1')
            s += '0';
          else
            s += '1';
        }
        for (long long int j = i + 1; j < n; j++) s += a[j];
        a = s;
      }
    } else {
      if (a[0] == '1') {
        v.push_back(1);
        if (a[0] == '1')
          a[0] = '0';
        else
          a[0] = '1';
        v.push_back(i + 1);
        string s = "";
        for (long long int j = i; j >= 0; j--) {
          if (a[j] == '1')
            s += '0';
          else
            s += '1';
        }
        for (long long int j = i + 1; j < n; j++) s += a[j];
        a = s;
      } else {
        v.push_back(i + 1);
        string s = "";
        for (long long int j = i; j >= 0; j--) {
          if (a[j] == '1')
            s += '0';
          else
            s += '1';
        }
        for (long long int j = i + 1; j < n; j++) s += a[j];
        a = s;
      }
    }
  }
  long long int sz = v.size();
  cout << sz << " ";
  for (long long int i = 0; i < sz; i++) {
    cout << v[i] << " ";
  }
  cout << "\n";
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t;
  cin >> t;
  for (long long int i = 1; i <= t; i++) {
    solve(i);
  }
  return 0;
}
