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

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

class C:
    def __init__(self, txt: str):
        self.q: D = None
        self.z: E = None
        self.p: D = None
        self.v: B = None
        self.txt = txt

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

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

g = A("g")
m = B("m")
h = C("h")
k = D("k")
e = E("e")
d = E("d")

g.q = d
g.z = h
g.t = h
g.o = e
m.o = d
m.t = e
h.q = k
h.p = k
h.z = e
h.v = m
k.r = d
e.t = g
e.x = d
d.t = g
d.x = e
assert h.p.r.t.q.t.txt == "
class A:
    def __init__(self, txt: str):
        self.q: E = None
        self.z: C = None
        self.t: C = None
        self.o: E = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.q: D = None
        self.z: E = None
        self.p: D = None
        self.v: B = None
        self.txt = txt

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

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

g = A("g")
m = B("m")
h = C("h")
k = D("k")
e = E("e")
d = E("d")

g.q = d
g.z = h
g.t = h
g.o = e
m.o = d
m.t = e
h.q = k
h.p = k
h.z = e
h.v = m
k.r = d
e.t = g
e.x = d
d.t = g
d.x = e
assert h.p.r.t.q.t.txt == "g"