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

class B:
    def __init__(self, txt: str):
        self.y: C = None
        self.txt = txt

class C:
    def __init__(self, txt: str):
        self.y: E = None
        self.q: A = None
        self.r: A = None
        self.txt = txt

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

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

g = A("g")
l = B("l")
i = C("i")
j = D("j")
a = E("a")
d = E("d")
h = A("h")

g.y = i
g.x = i
g.p = l
l.y = i
i.y = d
i.q = h
i.r = h
j.z = l
a.r = d
a.z = g
d.r = a
d.z = g
h.y = i
h.x = i
h.p = l
assert d.z.p.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: C = None
        self.x: C = None
        self.p: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.y: C = None
        self.txt = txt

class C:
    def __init__(self, txt: str):
        self.y: E = None
        self.q: A = None
        self.r: A = None
        self.txt = txt

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

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

g = A("g")
l = B("l")
i = C("i")
j = D("j")
a = E("a")
d = E("d")
h = A("h")

g.y = i
g.x = i
g.p = l
l.y = i
i.y = d
i.q = h
i.r = h
j.z = l
a.r = d
a.z = g
d.r = a
d.z = g
h.y = i
h.x = i
h.p = l
assert d.z.p.y.txt == "i"