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

f = A("f")
g = B("g")
b = B("b")
d = A("d")
e = A("e")
l = B("l")
i = A("i")
h = B("h")

f.p = l
g.o = f
b.o = f
d.p = h
e.p = b
l.o = i
i.p = l
h.o = e
assert i.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

f = A("f")
g = B("g")
b = B("b")
d = A("d")
e = A("e")
l = B("l")
i = A("i")
h = B("h")

f.p = l
g.o = f
b.o = f
d.p = h
e.p = b
l.o = i
i.p = l
h.o = e
assert i.p.o.p.txt == "l"