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

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

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

j = A("j")
k = B("k")
m = C("m")
h = A("h")

j.x = k
k.r = m
m.s = k
h.x = k
assert k.r.s.r.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.txt = txt

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

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

j = A("j")
k = B("k")
m = C("m")
h = A("h")

j.x = k
k.r = m
m.s = k
h.x = k
assert k.r.s.r.txt == "m"