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

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

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

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

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

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

h = A("h")
f = B("f")
b = C("b")
k = D("k")
e = E("e")
a = F("a")

h.s = k
f.s = b
f.t = b
f.p = e
f.w = h
b.t = f
b.p = f
k.w = h
k.r = f
k.u = b
e.w = h
a.y = e
a.w = e
assert h.s.u.p.w.txt == "
class A:
    def __init__(self, txt: str):
        self.s: D = None
        self.txt = txt

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

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

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

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

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

h = A("h")
f = B("f")
b = C("b")
k = D("k")
e = E("e")
a = F("a")

h.s = k
f.s = b
f.t = b
f.p = e
f.w = h
b.t = f
b.p = f
k.w = h
k.r = f
k.u = b
e.w = h
a.y = e
a.w = e
assert h.s.u.p.w.txt == "h"