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

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

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

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

e = A("e")
m = B("m")
a = C("a")
n = D("n")
k = C("k")
j = A("j")

e.t = j
e.o = n
m.r = j
a.w = m
n.o = m
n.p = e
n.z = j
k.w = m
j.t = e
j.o = n
assert k.w.r.t.txt == "
class A:
    def __init__(self, txt: str):
        self.t: A = None
        self.o: D = None
        self.txt = txt

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

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

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

e = A("e")
m = B("m")
a = C("a")
n = D("n")
k = C("k")
j = A("j")

e.t = j
e.o = n
m.r = j
a.w = m
n.o = m
n.p = e
n.z = j
k.w = m
j.t = e
j.o = n
assert k.w.r.t.txt == "e"