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

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

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

h = A("h")
c = B("c")
i = C("i")
j = C("j")

h.u = j
h.r = j
c.t = h
i.x = c
j.x = c
assert c.t.r.x.txt == "
class A:
    def __init__(self, txt: str):
        self.u: C = None
        self.r: C = None
        self.txt = txt

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

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

h = A("h")
c = B("c")
i = C("i")
j = C("j")

h.u = j
h.r = j
c.t = h
i.x = c
j.x = c
assert c.t.r.x.txt == "c"