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

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

c = A("c")
n = B("n")
a = B("a")
d = A("d")
b = B("b")

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

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

c = A("c")
n = B("n")
a = B("a")
d = A("d")
b = B("b")

c.v = d
c.r = a
n.s = d
a.s = d
d.v = c
d.r = b
b.s = d
assert c.v.r.s.r.txt == "b"