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

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

g = A("g")
b = B("b")
i = B("i")
a = A("a")

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

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

g = A("g")
b = B("b")
i = B("i")
a = A("a")

g.o = a
b.p = a
b.v = a
i.p = a
i.v = a
a.o = g
assert b.v.o.o.txt == "a"