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

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

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

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

h.q = i
h.r = i
b.r = j
b.u = i
i.y = h
j.r = b
j.u = i
assert b.u.y.r.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.r: C = None
        self.txt = txt

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

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

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

h.q = i
h.r = i
b.r = j
b.u = i
i.y = h
j.r = b
j.u = i
assert b.u.y.r.txt == "i"