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

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

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

j = A("j")
h = B("h")
l = C("l")
f = B("f")

j.x = f
j.u = l
h.r = f
h.u = j
h.x = l
l.x = h
f.r = h
f.u = j
f.x = l
assert j.u.x.u.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.u: C = None
        self.txt = txt

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

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

j = A("j")
h = B("h")
l = C("l")
f = B("f")

j.x = f
j.u = l
h.r = f
h.u = j
h.x = l
l.x = h
f.r = h
f.u = j
f.x = l
assert j.u.x.u.txt == "j"