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

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

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

j = A("j")
d = B("d")
b = C("b")
c = C("c")

j.u = c
j.y = b
j.v = b
d.u = j
d.y = j
b.q = j
b.r = c
b.w = c
c.q = j
c.r = b
c.w = b
assert c.q.u.q.txt == "
class A:
    def __init__(self, txt: str):
        self.u: C = None
        self.y: C = None
        self.v: C = None
        self.txt = txt

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

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

j = A("j")
d = B("d")
b = C("b")
c = C("c")

j.u = c
j.y = b
j.v = b
d.u = j
d.y = j
b.q = j
b.r = c
b.w = c
c.q = j
c.r = b
c.w = b
assert c.q.u.q.txt == "j"