#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e9;
const int MOD = 1e9 + 7;
const long long INF = 1e18;
const long double PI = 3.14159265358979323846;
template <typename T>
void read(vector<T>& a) {
  for (int i = 0; i < a.size(); ++i) cin >> a[i];
}
template <typename T>
void print(vector<T>& a) {
  for (int i = 0; i < a.size(); ++i) cout << a[i] << " ";
  cout << endl;
}
template <typename T>
void print2(vector<vector<T> >& a) {
  for (int i = 0; i < a.size(); ++i) {
    for (int j = 0; j < a[i].size(); ++j) {
      cout << a[i][j] << " ";
    }
    cout << endl;
  }
}
template <typename T>
void read2(vector<vector<T> >& a) {
  for (int i = 0; i < a.size(); ++i) {
    for (int j = 0; j < a[i].size(); ++j) {
      cin >> a[i][j];
    }
  }
}
void write() {
  int n;
  cin >> n;
  string s, t;
  cin >> s >> t;
  vector<int> ans;
  for (int i = n - 1; i >= 0; --i) {
    if (t[i] == s[0]) {
      if (i == 0) continue;
      ans.push_back(1);
      if (s[0] == '0')
        s[0] = '1';
      else
        s[0] = '0';
    }
    ans.push_back(i + 1);
    string tmp = "";
    for (int j = 0; j <= i; j++) {
      if (s[j] == '0')
        tmp += "1";
      else
        tmp += "0";
    }
    reverse((tmp).begin(), (tmp).end());
    for (int j = 0; j <= i; j++) {
      s[j] = tmp[j];
    }
  }
  cout << ans.size() << " ";
  print(ans);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  t = 1;
  cin >> t;
  for (int T = 0; T < t; ++T) write();
  return 0;
}
