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

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

e = A("e")
b = B("b")
k = A("k")
c = A("c")
d = B("d")
g = A("g")
j = B("j")
f = B("f")

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

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

e = A("e")
b = B("b")
k = A("k")
c = A("c")
d = B("d")
g = A("g")
j = B("j")
f = B("f")

e.p = b
b.o = g
k.p = j
c.p = b
d.o = k
g.p = d
j.o = c
f.o = g
assert k.p.o.p.o.p.txt == "d"