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

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

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

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

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

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

a.u = g
h.t = g
h.o = g
g.u = a
assert a.u.u.u.txt == "g"