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

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

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

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

f = A("f")
g = B("g")
m = C("m")
e = D("e")
i = B("i")

f.r = e
g.r = m
m.v = i
e.v = f
e.r = f
e.o = f
i.r = m
assert e.o.r.v.r.v.txt == "
class A:
    def __init__(self, txt: str):
        self.r: D = None
        self.txt = txt

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

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

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

f = A("f")
g = B("g")
m = C("m")
e = D("e")
i = B("i")

f.r = e
g.r = m
m.v = i
e.v = f
e.r = f
e.o = f
i.r = m
assert e.o.r.v.r.v.txt == "f"