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

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

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

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

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

class F:
    def __init__(self, txt: str):
        self.u: A = None
        self.t: A = None
        self.o: B = None
        self.txt = txt

h = A("h")
d = B("d")
b = C("b")
i = D("i")
m = E("m")
g = F("g")

h.p = m
h.w = i
d.z = b
d.r = m
d.p = g
b.t = i
b.o = d
i.r = d
i.o = m
i.z = h
m.t = g
m.w = b
g.u = h
g.t = h
g.o = d
assert g.t.w.o.t.u.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: E = None
        self.w: D = None
        self.txt = txt

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

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

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

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

class F:
    def __init__(self, txt: str):
        self.u: A = None
        self.t: A = None
        self.o: B = None
        self.txt = txt

h = A("h")
d = B("d")
b = C("b")
i = D("i")
m = E("m")
g = F("g")

h.p = m
h.w = i
d.z = b
d.r = m
d.p = g
b.t = i
b.o = d
i.r = d
i.o = m
i.z = h
m.t = g
m.w = b
g.u = h
g.t = h
g.o = d
assert g.t.w.o.t.u.p.txt == "m"