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

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

l = A("l")
i = B("i")
f = A("f")
k = B("k")
d = A("d")
a = A("a")
e = B("e")
b = B("b")
c = B("c")

l.o = a
i.q = k
i.p = b
f.o = l
k.q = e
k.p = c
d.o = a
a.o = l
e.q = i
e.p = k
b.q = k
b.p = c
c.q = e
c.p = i
assert l.o.o.o.o.o.o.o.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.txt = txt

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

l = A("l")
i = B("i")
f = A("f")
k = B("k")
d = A("d")
a = A("a")
e = B("e")
b = B("b")
c = B("c")

l.o = a
i.q = k
i.p = b
f.o = l
k.q = e
k.p = c
d.o = a
a.o = l
e.q = i
e.p = k
b.q = k
b.p = c
c.q = e
c.p = i
assert l.o.o.o.o.o.o.o.o.o.txt == "a"