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

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

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

d.o = f
d.r = a
a.v = d
i.v = d
f.o = d
f.r = h
h.v = d
assert d.r.v.o.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.r: B = None
        self.txt = txt

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

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

d.o = f
d.r = a
a.v = d
i.v = d
f.o = d
f.r = h
h.v = d
assert d.r.v.o.o.o.txt == "f"