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

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

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

a.u = h
l.w = h
j.w = a
h.u = a
assert a.u.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.w: A = None
        self.txt = txt

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

a.u = h
l.w = h
j.w = a
h.u = a
assert a.u.u.u.u.txt == "a"