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

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

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

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

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

h = A("h")
e = B("e")
g = C("g")
a = D("a")
f = E("f")
n = E("n")
m = D("m")
l = B("l")

h.v = a
e.t = g
e.w = l
g.r = m
a.x = h
a.q = h
a.z = f
a.w = g
a.o = e
f.s = g
n.s = g
m.x = h
m.q = h
m.z = n
m.w = g
m.o = e
l.t = g
l.w = e
assert f.s.r.z.s.r.txt == "
class A:
    def __init__(self, txt: str):
        self.v: D = None
        self.txt = txt

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

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

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

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

h = A("h")
e = B("e")
g = C("g")
a = D("a")
f = E("f")
n = E("n")
m = D("m")
l = B("l")

h.v = a
e.t = g
e.w = l
g.r = m
a.x = h
a.q = h
a.z = f
a.w = g
a.o = e
f.s = g
n.s = g
m.x = h
m.q = h
m.z = n
m.w = g
m.o = e
l.t = g
l.w = e
assert f.s.r.z.s.r.txt == "m"