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

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

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

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

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

e.r = a
a.v = g
a.z = j
a.r = e
g.p = e
g.u = e
j.w = e
j.o = g
j.p = g
assert a.z.w.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

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

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

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

e.r = a
a.v = g
a.z = j
a.r = e
g.p = e
g.u = e
j.w = e
j.o = g
j.p = g
assert a.z.w.r.txt == "a"