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

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

j = A("j")
f = B("f")
a = B("a")
k = B("k")
i = A("i")
n = A("n")
d = B("d")
l = A("l")

j.w = n
j.z = d
f.r = l
a.r = l
k.r = i
i.w = n
i.z = a
n.w = l
n.z = a
d.r = i
l.w = i
l.z = d
assert a.r.z.r.w.z.r.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.z: B = None
        self.txt = txt

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

j = A("j")
f = B("f")
a = B("a")
k = B("k")
i = A("i")
n = A("n")
d = B("d")
l = A("l")

j.w = n
j.z = d
f.r = l
a.r = l
k.r = i
i.w = n
i.z = a
n.w = l
n.z = a
d.r = i
l.w = i
l.z = d
assert a.r.z.r.w.z.r.w.txt == "i"