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

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

j = A("j")
e = B("e")
g = B("g")
l = B("l")
m = A("m")
k = B("k")
a = A("a")

j.z = m
j.r = e
e.w = l
g.w = l
l.w = g
m.z = a
m.r = k
k.w = e
a.z = j
a.r = g
assert k.w.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.r: B = None
        self.txt = txt

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

j = A("j")
e = B("e")
g = B("g")
l = B("l")
m = A("m")
k = B("k")
a = A("a")

j.z = m
j.r = e
e.w = l
g.w = l
l.w = g
m.z = a
m.r = k
k.w = e
a.z = j
a.r = g
assert k.w.w.w.w.txt == "l"