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

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

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

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

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

k = A("k")
c = B("c")
f = C("f")
m = D("m")
h = E("h")

k.x = m
c.u = m
c.z = m
c.q = h
f.p = m
f.s = k
m.x = c
m.v = h
m.r = k
m.p = k
m.q = f
h.x = f
assert m.v.x.p.p.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: D = None
        self.txt = txt

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

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

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

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

k = A("k")
c = B("c")
f = C("f")
m = D("m")
h = E("h")

k.x = m
c.u = m
c.z = m
c.q = h
f.p = m
f.s = k
m.x = c
m.v = h
m.r = k
m.p = k
m.q = f
h.x = f
assert m.v.x.p.p.x.txt == "m"