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

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

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

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

d = A("d")
f = B("f")
h = C("h")
c = D("c")
n = D("n")

d.o = f
d.v = f
d.r = n
f.q = h
h.v = d
c.z = d
c.v = d
n.z = d
n.v = d
assert d.r.v.r.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.r: D = None
        self.v: B = None
        self.txt = txt

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

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

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

d = A("d")
f = B("f")
h = C("h")
c = D("c")
n = D("n")

d.o = f
d.v = f
d.r = n
f.q = h
h.v = d
c.z = d
c.v = d
n.z = d
n.v = d
assert d.r.v.r.txt == "n"