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

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

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

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

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

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

b = A("b")
m = B("m")
h = C("h")
e = D("e")
i = E("i")
a = F("a")

b.o = h
m.y = b
m.s = a
m.z = h
m.r = i
h.r = b
e.o = h
e.p = h
e.q = m
e.t = i
e.s = b
e.w = b
i.q = h
i.t = e
a.s = h
a.r = h
a.w = h
a.p = e
assert m.r.q.r.o.r.txt == "
class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.txt = txt

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

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

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

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

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

b = A("b")
m = B("m")
h = C("h")
e = D("e")
i = E("i")
a = F("a")

b.o = h
m.y = b
m.s = a
m.z = h
m.r = i
h.r = b
e.o = h
e.p = h
e.q = m
e.t = i
e.s = b
e.w = b
i.q = h
i.t = e
a.s = h
a.r = h
a.w = h
a.p = e
assert m.r.q.r.o.r.txt == "b"