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

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

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

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

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

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

d.v = b
d.y = n
a.z = n
n.z = a
b.v = d
b.y = n
assert b.v.v.v.txt == "d"