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

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

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

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

l.w = g
g.v = l
g.x = h
h.q = b
h.x = l
h.p = g
b.w = g
assert l.w.v.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

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

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

l.w = g
g.v = l
g.x = h
h.q = b
h.x = l
h.p = g
b.w = g
assert l.w.v.w.txt == "g"