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

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

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

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

d = A("d")
k = B("k")
c = C("c")
j = D("j")
m = B("m")
b = D("b")
a = A("a")
i = D("i")

d.y = a
d.u = k
k.t = b
c.t = d
j.x = m
j.q = c
j.p = b
j.r = a
m.t = i
b.x = m
b.q = c
b.p = i
b.r = d
a.y = d
a.u = m
i.x = k
i.q = c
i.p = b
i.r = a
assert d.u.t.q.t.y.u.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.u: B = None
        self.txt = txt

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

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

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

d = A("d")
k = B("k")
c = C("c")
j = D("j")
m = B("m")
b = D("b")
a = A("a")
i = D("i")

d.y = a
d.u = k
k.t = b
c.t = d
j.x = m
j.q = c
j.p = b
j.r = a
m.t = i
b.x = m
b.q = c
b.p = i
b.r = d
a.y = d
a.u = m
i.x = k
i.q = c
i.p = b
i.r = a
assert d.u.t.q.t.y.u.txt == "m"