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

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

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

b = A("b")
n = B("n")
h = C("h")
l = A("l")

b.r = l
b.q = l
n.q = l
n.z = h
h.w = n
h.y = n
h.q = b
l.r = b
l.q = b
assert n.z.q.q.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.q: A = None
        self.txt = txt

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

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

b = A("b")
n = B("n")
h = C("h")
l = A("l")

b.r = l
b.q = l
n.q = l
n.z = h
h.w = n
h.y = n
h.q = b
l.r = b
l.q = b
assert n.z.q.q.r.txt == "b"