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

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

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

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

h = A("h")
f = B("f")
d = C("d")
a = D("a")

h.r = f
f.u = h
f.q = a
f.z = a
d.s = f
d.r = f
d.t = h
a.s = h
a.p = d
a.v = f
assert a.v.q.p.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

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

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

h = A("h")
f = B("f")
d = C("d")
a = D("a")

h.r = f
f.u = h
f.q = a
f.z = a
d.s = f
d.r = f
d.t = h
a.s = h
a.p = d
a.v = f
assert a.v.q.p.txt == "d"