#include <bits/stdc++.h>
using namespace std;
void dbg_out() { cerr << "\b\b]\n"; }
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) {
  cerr << H << ", ";
  dbg_out(T...);
}
void solve() {
  int n;
  cin >> n;
  string s, t;
  cin >> s >> t;
  auto oper = [&](int x) {
    for (int i = 0; i <= x; ++i) {
      if (s[i] == '1')
        s[i] = '0';
      else
        s[i] = '1';
    }
    reverse(s.begin(), s.begin() + x + 1);
  };
  vector<int> ans;
  for (int i = n - 1; i >= 0; --i) {
    if (s[i] == t[i]) continue;
    if (t[i] == '1') {
      if (s[0] != '0') {
        ans.push_back(0);
        oper(0);
      }
      oper(i);
    } else {
      if (s[0] != '1') {
        ans.push_back(0);
        oper(0);
      }
      oper(i);
    }
    ans.push_back(i);
  }
  cout << (int)ans.size() << " ";
  for (int i : ans) cout << (i + 1) << ' ';
  cout << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
