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

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

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

class D:
    def __init__(self, txt: str):
        self.r: C = None
        self.w: C = None
        self.z: C = None
        self.txt = txt

h = A("h")
m = B("m")
g = C("g")
c = D("c")
f = B("f")

h.p = c
m.v = g
m.s = c
m.z = f
g.q = c
c.r = g
c.w = g
c.z = g
f.v = g
f.s = c
f.z = m
assert g.q.w.q.r.txt == "
class A:
    def __init__(self, txt: str):
        self.p: D = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.r: C = None
        self.w: C = None
        self.z: C = None
        self.txt = txt

h = A("h")
m = B("m")
g = C("g")
c = D("c")
f = B("f")

h.p = c
m.v = g
m.s = c
m.z = f
g.q = c
c.r = g
c.w = g
c.z = g
f.v = g
f.s = c
f.z = m
assert g.q.w.q.r.txt == "g"