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

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

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

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

a = A("a")
g = B("g")
h = C("h")
b = D("b")
k = A("k")
c = A("c")

a.v = g
a.z = k
g.z = h
h.r = a
b.q = a
b.z = a
b.t = h
k.v = g
k.z = a
c.v = g
c.z = a
assert c.z.v.z.r.z.txt == "
class A:
    def __init__(self, txt: str):
        self.v: B = None
        self.z: A = None
        self.txt = txt

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

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

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

a = A("a")
g = B("g")
h = C("h")
b = D("b")
k = A("k")
c = A("c")

a.v = g
a.z = k
g.z = h
h.r = a
b.q = a
b.z = a
b.t = h
k.v = g
k.z = a
c.v = g
c.z = a
assert c.z.v.z.r.z.txt == "k"