RippleCarry Adder

All submissions for this problem are available.
Amortized analysis deals with analyzing the average amount of work done per operation over a series of operations. In some cases, the average amount of work done per operation is dramatically less than the worst case analysis indicates.
A typical example is counting the number of times a bit is flipped in a ripplecarry counter. A ripplecarry counter is an implementation of a binary counter where incrementing from B to B+1 is done in the following manner. Say the binary number is represented as B = b_{n1}b__{n2}...b__{1}b_{0} where b_{i} is the bit corresponding to 2^{i}. B is increased to B+1 in the following manner:
i := 0
while b_{i} == 1
b_{i} := 0
i := i+1
b_{i} := 1
This doesn't account for overflow when increasing from 2^{n}1 to 2^{n}, but we'll ignore that error for this problem.
Each time a bit is changed from 0 to 1 or from 1 to 0 we say the bit is "flipped". In the worst case, we may have to flip every bit. However, a standard result says the average number of bits flipped per increment when counting from 0 to 2^{n}1 is less than 2.
Being the curious sort, you decide to explore this result in a slightly more general setting. That is, you want to know how many bits are flipped when the counter is incremented from a number a to b where a < b.
Input
The first line denotes the number of test cases (about 20).
Each test case consists of three lines. The first contains a single integer n between 1 and 100,000 denoting the number of bits in the counter. The second line contains the number a written in binary and the third line contains the number b written in binary. Both a and b are described using exactly n bits.
Output
The output for each test case consists of a single line that describes the total number of bits flipped when the counter is increased from a to b. This number should be expressed in binary with the most significant bit being 1 (i.e. no leading zeros should pad the output).
Example
Input: 3 1 0 1 2 00 11 3 011 100 Output: 1 100 11
Author:  friggstad 
Tester:  pieguy 
Editorial  http://discuss.codechef.com/problems/RIPPLE 
Tags  cook01, friggstad, medium 
Date Added:  8052010 
Time Limit:  0.348837 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, kotlin, PERL6, TEXT, SCM chicken, PYP3, CLOJ, COB, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 