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

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

d = A("d")
g = B("g")
b = B("b")
h = A("h")

d.u = h
g.s = h
g.t = b
b.s = h
b.t = g
h.u = d
assert h.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.s: A = None
        self.t: B = None
        self.txt = txt

d = A("d")
g = B("g")
b = B("b")
h = A("h")

d.u = h
g.s = h
g.t = b
b.s = h
b.t = g
h.u = d
assert h.u.u.u.txt == "d"