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

class B:
    def __init__(self, txt: str):
        self.x: D = None
        self.z: C = None
        self.txt = txt

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

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

c = A("c")
l = B("l")
i = C("i")
h = D("h")
b = B("b")
k = A("k")
d = D("d")
j = D("j")
n = D("n")
f = C("f")

c.x = k
l.x = j
l.z = i
i.r = b
i.x = f
h.w = k
h.q = i
h.z = i
h.p = l
b.x = d
b.z = f
k.x = c
d.w = k
d.q = i
d.z = f
d.p = b
j.w = c
j.q = f
j.z = f
j.p = b
n.w = c
n.q = i
n.z = i
n.p = b
f.r = b
f.x = i
assert j.q.r.x.q.x.x.r.x.w.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.x: D = None
        self.z: C = None
        self.txt = txt

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

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

c = A("c")
l = B("l")
i = C("i")
h = D("h")
b = B("b")
k = A("k")
d = D("d")
j = D("j")
n = D("n")
f = C("f")

c.x = k
l.x = j
l.z = i
i.r = b
i.x = f
h.w = k
h.q = i
h.z = i
h.p = l
b.x = d
b.z = f
k.x = c
d.w = k
d.q = i
d.z = f
d.p = b
j.w = c
j.q = f
j.z = f
j.p = b
n.w = c
n.q = i
n.z = i
n.p = b
f.r = b
f.x = i
assert j.q.r.x.q.x.x.r.x.w.txt == "k"