#include <bits/stdc++.h>
using namespace std;
const long long N = 998244353;
string make(string &s1, int n) {
  if (n == -1) s1;
  string s = "";
  for (int i = 0; i < n; i++) {
    if (s1[i] == '1')
      s += '0';
    else
      s += '1';
  }
  reverse(s.begin(), s.end());
  for (int i = n; i < s1.size(); i++) {
    s += s1[i];
  }
  return s;
}
void solve() {
  int n;
  cin >> n;
  string s1, s2;
  cin >> s1 >> s2;
  int x = n - 1;
  for (; x >= 0; x--) {
    if (s1[x] != s2[x]) break;
  }
  if (x == -1) {
    cout << 0 << endl;
    return;
  }
  int ans = 0;
  vector<int> result;
  for (int i = x; i >= 0; i--) {
    if (s1[i] == s2[i])
      continue;
    else if (s1[0] == s1[i]) {
      s1 = make(s1, i + 1);
      ans++;
      result.push_back(i + 1);
    } else {
      if (s1[0] == '1')
        s1[0] = '0';
      else
        s1[0] = '1';
      s1 = make(s1, i + 1);
      ans += 2;
      result.push_back(1);
      result.push_back(i + 1);
    }
  }
  cout << ans << " ";
  for (auto it : result) cout << it << " ";
  cout << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC
       << "ms\n";
  return 0;
}
