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

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

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

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

g = A("g")
e = B("e")
d = C("d")
j = D("j")
l = B("l")

g.z = l
e.p = d
e.v = g
d.r = g
d.y = g
d.p = j
d.z = j
j.t = d
l.p = d
l.v = g
assert j.t.r.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

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

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

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

g = A("g")
e = B("e")
d = C("d")
j = D("j")
l = B("l")

g.z = l
e.p = d
e.v = g
d.r = g
d.y = g
d.p = j
d.z = j
j.t = d
l.p = d
l.v = g
assert j.t.r.z.txt == "l"