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

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

c = A("c")
d = B("d")
m = B("m")
f = B("f")
i = B("i")
n = A("n")
a = A("a")

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

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

c = A("c")
d = B("d")
m = B("m")
f = B("f")
i = B("i")
n = A("n")
a = A("a")

c.r = m
c.z = a
d.v = i
d.r = f
m.v = f
m.r = f
f.v = d
f.r = m
i.v = m
i.r = m
n.r = i
n.z = c
a.r = d
a.z = n
assert f.r.v.v.r.txt == "f"