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

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

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

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

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

k = A("k")
n = B("n")
m = C("m")
j = D("j")
d = E("d")
i = A("i")

k.t = m
k.p = i
n.s = k
n.t = m
n.z = m
n.w = d
m.x = d
m.w = k
j.q = d
d.x = n
i.t = m
i.p = k
assert n.w.x.t.txt == "
class A:
    def __init__(self, txt: str):
        self.t: C = None
        self.p: A = None
        self.txt = txt

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

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

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

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

k = A("k")
n = B("n")
m = C("m")
j = D("j")
d = E("d")
i = A("i")

k.t = m
k.p = i
n.s = k
n.t = m
n.z = m
n.w = d
m.x = d
m.w = k
j.q = d
d.x = n
i.t = m
i.p = k
assert n.w.x.t.txt == "m"