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

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

c = A("c")
n = B("n")
d = A("d")
b = A("b")
f = B("f")
i = B("i")

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

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

c = A("c")
n = B("n")
d = A("d")
b = A("b")
f = B("f")
i = B("i")

c.r = i
c.v = b
n.y = f
d.r = n
d.v = b
b.r = n
b.v = d
f.y = i
i.y = n
assert d.v.r.y.y.y.txt == "n"