class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

l = A("l")
h = B("h")
b = B("b")
g = A("g")
n = A("n")
c = B("c")
f = A("f")
i = A("i")
k = A("k")

l.o = c
h.q = c
b.q = c
g.o = b
n.o = c
c.q = b
f.o = c
i.o = c
k.o = h
assert c.q.q.q.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

l = A("l")
h = B("h")
b = B("b")
g = A("g")
n = A("n")
c = B("c")
f = A("f")
i = A("i")
k = A("k")

l.o = c
h.q = c
b.q = c
g.o = b
n.o = c
c.q = b
f.o = c
i.o = c
k.o = h
assert c.q.q.q.q.q.q.q.txt == "b"