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

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

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

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

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

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

j.p = d
j.v = d
g.o = j
g.p = j
d.p = j
d.v = j
assert d.v.v.p.txt == "j"