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

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

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

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

f.u = j
f.y = m
j.p = f
h.q = m
h.u = j
k.q = m
k.u = j
m.q = k
m.u = j
assert j.p.u.p.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.y: C = None
        self.txt = txt

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

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

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

f.u = j
f.y = m
j.p = f
h.q = m
h.u = j
k.q = m
k.u = j
m.q = k
m.u = j
assert j.p.u.p.txt == "f"