class A:
    def __init__(self, txt: str):
        self.s: C = None
        self.z: C = 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.v: A = None
        self.txt = txt

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

e = A("e")
g = B("g")
a = C("a")
h = D("h")

e.s = a
e.z = a
g.z = a
a.v = e
h.t = g
h.o = g
h.r = a
assert g.z.v.s.v.txt == "
class A:
    def __init__(self, txt: str):
        self.s: C = None
        self.z: C = 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.v: A = None
        self.txt = txt

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

e = A("e")
g = B("g")
a = C("a")
h = D("h")

e.s = a
e.z = a
g.z = a
a.v = e
h.t = g
h.o = g
h.r = a
assert g.z.v.s.v.txt == "e"