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

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

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

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

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

g.z = j
g.p = l
j.t = g
j.q = l
l.x = j
l.z = d
d.z = l
d.w = l
d.x = l
d.t = a
e.z = j
e.p = l
a.z = l
a.w = l
a.x = l
a.t = d
assert g.z.t.p.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.p: C = None
        self.txt = txt

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

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

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

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

g.z = j
g.p = l
j.t = g
j.q = l
l.x = j
l.z = d
d.z = l
d.w = l
d.x = l
d.t = a
e.z = j
e.p = l
a.z = l
a.w = l
a.x = l
a.t = d
assert g.z.t.p.z.txt == "d"