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

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

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

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

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

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

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

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

h.p = f
h.u = j
f.p = h
f.y = h
f.w = h
j.t = f
j.q = f
j.u = h
assert j.u.u.t.txt == "f"