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

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

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

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

c = A("c")
d = B("d")
h = C("h")
a = D("a")
e = B("e")
i = A("i")
f = C("f")
j = B("j")
k = C("k")

c.w = a
c.t = k
d.t = c
h.r = d
a.x = c
e.t = i
i.w = a
i.t = k
f.r = e
j.t = c
k.r = d
assert j.t.t.r.t.t.r.t.txt == "
class A:
    def __init__(self, txt: str):
        self.w: D = None
        self.t: C = None
        self.txt = txt

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

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

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

c = A("c")
d = B("d")
h = C("h")
a = D("a")
e = B("e")
i = A("i")
f = C("f")
j = B("j")
k = C("k")

c.w = a
c.t = k
d.t = c
h.r = d
a.x = c
e.t = i
i.w = a
i.t = k
f.r = e
j.t = c
k.r = d
assert j.t.t.r.t.t.r.t.txt == "c"