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

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

a = A("a")
c = B("c")
j = B("j")
k = B("k")
i = B("i")
h = A("h")
b = A("b")

a.o = j
c.p = i
j.p = k
k.p = c
i.p = j
h.o = i
b.o = c
assert k.p.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.txt = txt

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

a = A("a")
c = B("c")
j = B("j")
k = B("k")
i = B("i")
h = A("h")
b = A("b")

a.o = j
c.p = i
j.p = k
k.p = c
i.p = j
h.o = i
b.o = c
assert k.p.p.p.p.txt == "k"