class A:
    def __init__(self, txt: str):
        self.q: D = None
        self.v: A = None
        self.r: A = None
        self.txt = txt

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

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

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

class E:
    def __init__(self, txt: str):
        self.y: D = None
        self.u: C = None
        self.x: C = None
        self.txt = txt

c = A("c")
a = B("a")
g = C("g")
b = D("b")
m = E("m")
f = E("f")
e = A("e")
h = D("h")

c.q = h
c.v = e
c.r = e
a.w = h
a.q = h
a.u = g
g.w = m
g.t = f
b.s = h
m.y = h
m.u = g
m.x = g
f.y = h
f.u = g
f.x = g
e.q = b
e.v = c
e.r = c
h.s = b
assert h.s.s.s.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.q: D = None
        self.v: A = None
        self.r: A = None
        self.txt = txt

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

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

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

class E:
    def __init__(self, txt: str):
        self.y: D = None
        self.u: C = None
        self.x: C = None
        self.txt = txt

c = A("c")
a = B("a")
g = C("g")
b = D("b")
m = E("m")
f = E("f")
e = A("e")
h = D("h")

c.q = h
c.v = e
c.r = e
a.w = h
a.q = h
a.u = g
g.w = m
g.t = f
b.s = h
m.y = h
m.u = g
m.x = g
f.y = h
f.u = g
f.x = g
e.q = b
e.v = c
e.r = c
h.s = b
assert h.s.s.s.s.s.s.txt == "h"