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

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

d = A("d")
k = B("k")
l = B("l")
n = A("n")
i = A("i")
j = A("j")
m = A("m")
b = B("b")

d.x = l
k.o = b
l.o = b
n.x = l
i.x = k
j.x = b
m.x = k
b.o = l
assert n.x.o.o.o.o.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.txt = txt

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

d = A("d")
k = B("k")
l = B("l")
n = A("n")
i = A("i")
j = A("j")
m = A("m")
b = B("b")

d.x = l
k.o = b
l.o = b
n.x = l
i.x = k
j.x = b
m.x = k
b.o = l
assert n.x.o.o.o.o.o.o.txt == "l"