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

class B:
    def __init__(self, txt: str):
        self.x: C = None
        self.z: D = None
        self.q: D = None
        self.s: A = None
        self.txt = txt

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

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

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

a = A("a")
f = B("f")
k = C("k")
b = D("b")
d = E("d")

a.s = d
a.p = k
f.x = k
f.z = b
f.q = b
f.s = a
k.u = f
k.x = f
k.p = f
k.t = f
b.t = a
b.q = d
d.w = a
assert f.s.s.w.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: E = None
        self.p: C = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.x: C = None
        self.z: D = None
        self.q: D = None
        self.s: A = None
        self.txt = txt

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

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

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

a = A("a")
f = B("f")
k = C("k")
b = D("b")
d = E("d")

a.s = d
a.p = k
f.x = k
f.z = b
f.q = b
f.s = a
k.u = f
k.x = f
k.p = f
k.t = f
b.t = a
b.q = d
d.w = a
assert f.s.s.w.s.txt == "d"