class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.q: E = None
        self.p: E = None
        self.txt = txt

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

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

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

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

a = A("a")
d = B("d")
c = C("c")
e = D("e")
g = E("g")
b = A("b")

a.x = b
a.q = g
a.p = g
d.q = g
d.p = g
d.w = a
d.t = a
d.z = c
c.w = g
c.z = d
c.t = d
e.y = a
e.p = a
e.r = a
e.x = c
e.o = c
g.z = c
b.x = a
b.q = g
b.p = g
assert g.z.z.p.z.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.q: E = None
        self.p: E = None
        self.txt = txt

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

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

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

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

a = A("a")
d = B("d")
c = C("c")
e = D("e")
g = E("g")
b = A("b")

a.x = b
a.q = g
a.p = g
d.q = g
d.p = g
d.w = a
d.t = a
d.z = c
c.w = g
c.z = d
c.t = d
e.y = a
e.p = a
e.r = a
e.x = c
e.o = c
g.z = c
b.x = a
b.q = g
b.p = g
assert g.z.z.p.z.txt == "c"