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

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

a = A("a")
e = B("e")
b = B("b")
d = B("d")
h = B("h")
l = B("l")
k = A("k")
f = B("f")
j = B("j")

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

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

a = A("a")
e = B("e")
b = B("b")
d = B("d")
h = B("h")
l = B("l")
k = A("k")
f = B("f")
j = B("j")

a.p = k
e.o = f
b.o = j
d.o = b
h.o = e
l.o = b
k.p = a
f.o = b
j.o = e
assert l.o.o.o.o.o.txt == "b"