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

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

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

class D:
    def __init__(self, txt: str):
        self.r: C = None
        self.t: E = None
        self.p: B = None
        self.y: B = None
        self.w: C = None
        self.txt = txt

class E:
    def __init__(self, txt: str):
        self.s: B = None
        self.txt = txt

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

k.s = h
k.r = h
m.x = k
f.t = c
f.r = b
c.r = d
c.w = d
c.t = b
c.p = m
c.y = m
b.s = m
h.s = k
h.r = k
n.t = c
n.r = b
d.t = c
d.r = b
assert f.t.t.s.x.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.r: A = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.r: C = None
        self.t: E = None
        self.p: B = None
        self.y: B = None
        self.w: C = None
        self.txt = txt

class E:
    def __init__(self, txt: str):
        self.s: B = None
        self.txt = txt

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

k.s = h
k.r = h
m.x = k
f.t = c
f.r = b
c.r = d
c.w = d
c.t = b
c.p = m
c.y = m
b.s = m
h.s = k
h.r = k
n.t = c
n.r = b
d.t = c
d.r = b
assert f.t.t.s.x.s.s.txt == "k"