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

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

f = A("f")
i = B("i")
j = B("j")
m = B("m")
c = A("c")

f.z = c
f.v = m
i.z = j
i.r = c
j.z = i
j.r = f
m.z = j
m.r = f
c.z = f
c.v = i
assert f.z.z.v.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.v: B = None
        self.txt = txt

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

f = A("f")
i = B("i")
j = B("j")
m = B("m")
c = A("c")

f.z = c
f.v = m
i.z = j
i.r = c
j.z = i
j.r = f
m.z = j
m.r = f
c.z = f
c.v = i
assert f.z.z.v.z.txt == "j"