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

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

d = A("d")
m = B("m")
j = A("j")

d.v = j
m.p = d
j.v = d
assert d.v.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: A = None
        self.txt = txt

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

d = A("d")
m = B("m")
j = A("j")

d.v = j
m.p = d
j.v = d
assert d.v.v.v.txt == "j"