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

class B:
    def __init__(self, txt: str):
        self.x: E = None
        self.s: C = None
        self.w: A = None
        self.r: D = None
        self.p: D = None
        self.txt = txt

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

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

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

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

f.z = h
e.x = d
e.s = m
e.w = n
e.r = a
e.p = a
m.p = a
m.z = e
a.p = n
a.q = e
a.v = h
d.r = a
d.y = n
n.z = f
h.z = n
assert d.y.z.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.x: E = None
        self.s: C = None
        self.w: A = None
        self.r: D = None
        self.p: D = None
        self.txt = txt

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

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

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

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

f.z = h
e.x = d
e.s = m
e.w = n
e.r = a
e.p = a
m.p = a
m.z = e
a.p = n
a.q = e
a.v = h
d.r = a
d.y = n
n.z = f
h.z = n
assert d.y.z.z.z.z.txt == "f"