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

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

j = A("j")
a = B("a")
g = A("g")
h = B("h")

j.t = g
a.s = h
a.o = j
g.t = j
h.s = a
h.o = j
assert g.t.t.t.t.txt == "
class A:
    def __init__(self, txt: str):
        self.t: A = None
        self.txt = txt

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

j = A("j")
a = B("a")
g = A("g")
h = B("h")

j.t = g
a.s = h
a.o = j
g.t = j
h.s = a
h.o = j
assert g.t.t.t.t.txt == "g"