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

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

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

f = A("f")
g = B("g")
b = C("b")
c = A("c")
m = C("m")
d = A("d")
l = B("l")

f.x = m
g.s = l
b.x = d
b.q = g
b.v = l
c.x = b
m.x = d
m.q = l
m.v = g
d.x = m
l.s = g
assert d.x.q.s.txt == "
class A:
    def __init__(self, txt: str):
        self.x: C = None
        self.txt = txt

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

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

f = A("f")
g = B("g")
b = C("b")
c = A("c")
m = C("m")
d = A("d")
l = B("l")

f.x = m
g.s = l
b.x = d
b.q = g
b.v = l
c.x = b
m.x = d
m.q = l
m.v = g
d.x = m
l.s = g
assert d.x.q.s.txt == "g"