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

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

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

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

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

i.t = e
g.r = a
g.p = a
g.z = e
g.u = e
e.p = g
e.w = i
e.x = h
h.r = g
h.u = g
c.t = e
a.r = g
a.u = g
assert i.t.x.u.r.u.p.txt == "
class A:
    def __init__(self, txt: str):
        self.t: C = None
        self.txt = txt

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

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

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

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

i.t = e
g.r = a
g.p = a
g.z = e
g.u = e
e.p = g
e.w = i
e.x = h
h.r = g
h.u = g
c.t = e
a.r = g
a.u = g
assert i.t.x.u.r.u.p.txt == "a"