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

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

h = A("h")
d = B("d")
f = B("f")

h.o = f
d.u = h
d.p = h
f.u = h
f.p = h
assert d.p.o.u.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.txt = txt

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

h = A("h")
d = B("d")
f = B("f")

h.o = f
d.u = h
d.p = h
f.u = h
f.p = h
assert d.p.o.u.txt == "h"