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

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

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

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

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

j.q = e
j.t = i
k.s = e
k.t = d
c.s = k
e.w = i
e.z = c
e.r = c
e.q = d
d.w = i
d.z = c
d.r = c
d.q = e
i.q = d
i.t = j
assert k.s.w.t.t.t.txt == "
class A:
    def __init__(self, txt: str):
        self.q: D = None
        self.t: A = None
        self.txt = txt

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

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

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

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

j.q = e
j.t = i
k.s = e
k.t = d
c.s = k
e.w = i
e.z = c
e.r = c
e.q = d
d.w = i
d.z = c
d.r = c
d.q = e
i.q = d
i.t = j
assert k.s.w.t.t.t.txt == "j"