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

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

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

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

l.r = h
c.w = b
c.x = h
j.r = i
j.w = h
j.q = c
h.r = l
i.w = j
i.x = l
b.r = i
b.q = i
b.w = h
assert j.q.x.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.txt = txt

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

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

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

l.r = h
c.w = b
c.x = h
j.r = i
j.w = h
j.q = c
h.r = l
i.w = j
i.x = l
b.r = i
b.q = i
b.w = h
assert j.q.x.r.txt == "l"