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

class B:
    def __init__(self, txt: str):
        self.q: C = None
        self.z: E = None
        self.u: A = None
        self.s: E = None
        self.v: C = None
        self.r: F = None
        self.txt = txt

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

class D:
    def __init__(self, txt: str):
        self.u: A = None
        self.y: A = None
        self.t: F = None
        self.o: C = None
        self.z: E = None
        self.txt = txt

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

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

d = A("d")
c = B("c")
m = C("m")
g = D("g")
n = E("n")
h = F("h")

d.w = n
c.q = m
c.v = m
c.z = n
c.s = n
c.u = d
c.r = h
m.w = h
g.u = d
g.y = d
g.t = h
g.o = m
g.z = n
n.z = g
n.q = h
h.w = m
assert h.w.w.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: E = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.q: C = None
        self.z: E = None
        self.u: A = None
        self.s: E = None
        self.v: C = None
        self.r: F = None
        self.txt = txt

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

class D:
    def __init__(self, txt: str):
        self.u: A = None
        self.y: A = None
        self.t: F = None
        self.o: C = None
        self.z: E = None
        self.txt = txt

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

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

d = A("d")
c = B("c")
m = C("m")
g = D("g")
n = E("n")
h = F("h")

d.w = n
c.q = m
c.v = m
c.z = n
c.s = n
c.u = d
c.r = h
m.w = h
g.u = d
g.y = d
g.t = h
g.o = m
g.z = n
n.z = g
n.q = h
h.w = m
assert h.w.w.w.w.w.txt == "m"