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

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

j = A("j")
l = B("l")
e = B("e")
k = A("k")
f = B("f")

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

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

j = A("j")
l = B("l")
e = B("e")
k = A("k")
f = B("f")

j.z = k
j.r = k
l.r = f
l.w = j
e.r = l
e.w = j
k.z = j
k.r = j
f.r = l
f.w = j
assert k.z.r.r.txt == "j"