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

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

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

g.v = f
g.t = h
h.x = g
h.o = f
f.v = g
f.t = h
assert h.x.t.x.txt == "
class A:
    def __init__(self, txt: str):
        self.v: A = None
        self.t: B = None
        self.txt = txt

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

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

g.v = f
g.t = h
h.x = g
h.o = f
f.v = g
f.t = h
assert h.x.t.x.txt == "g"