#include <bits/stdc++.h>
using namespace std;
long long int a[2005];
long long int cnt[2005];
long long int b[2005];
long long int vis[2005];
vector<long long int> v;
vector<long long int> vv;
vector<long long int> ans;
long long int prime[2005];
bool pr[2005];
set<char> st;
priority_queue<long long int> bob;
priority_queue<long long int> ali;
priority_queue<long long int> bth;
queue<long long int> q;
map<long long int, long long int> mp;
long long int taken[105];
map<long long int, long long int>::iterator it;
map<long long int, vector<long long int> > ck;
string ss, tt;
long long int pos[205];
long long int afs[205];
long long int pre[2005];
long long int aa[2005];
long long int cs[27];
long long int ct[27];
long long int power(long long int k, long long int i) {
  long long int res = 1;
  for (long long int j = 1; j <= i; j++) {
    res = res * k;
  }
  return res;
}
int main() {
  long long int n, i, j, k, t, m;
  cin >> t;
  long long int minis;
  long long int res;
  long long int x, y;
  long long int pp;
  string fg;
  long long int l, r;
  long long int h;
  long long int p, q;
  string tt;
  while (t--) {
    v.clear();
    cin >> n;
    cin >> ss >> tt;
    string fg;
    long long int kk = n;
    res = 0;
    for (i = n - 1; i >= 0; i--) {
      if (ss[i] == tt[i]) {
        kk--;
        continue;
      } else {
        if (ss[0] == tt[i]) {
          res = res + 1;
          v.push_back(1);
          if (ss[0] == '0')
            ss[0] = '1';
          else
            ss[0] = '0';
        }
        fg.clear();
        for (j = 0; j <= i; j++) {
          if (ss[j] == '0')
            fg.push_back('1');
          else
            fg.push_back('0');
        }
        reverse(fg.begin(), fg.end());
        res = res + 1;
        v.push_back(kk);
        for (j = 0; j <= i; j++) {
          ss[j] = fg[j];
        }
      }
      kk--;
    }
    cout << res << " ";
    for (i = 0; i < v.size(); i++) cout << v[i] << " ";
    cout << '\n';
  }
  return 0;
}
