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

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

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

l = A("l")
m = B("m")
c = C("c")

l.w = m
l.r = m
l.q = c
m.x = c
m.q = c
c.w = m
c.y = m
c.x = l
assert l.r.q.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.q: C = None
        self.r: B = None
        self.txt = txt

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

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

l = A("l")
m = B("m")
c = C("c")

l.w = m
l.r = m
l.q = c
m.x = c
m.q = c
c.w = m
c.y = m
c.x = l
assert l.r.q.w.txt == "m"