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

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

g = A("g")
c = B("c")
h = B("h")

g.o = c
c.p = g
h.p = g
assert h.p.o.p.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.txt = txt

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

g = A("g")
c = B("c")
h = B("h")

g.o = c
c.p = g
h.p = g
assert h.p.o.p.txt == "g"