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

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

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

m = A("m")
d = B("d")
i = C("i")
j = A("j")
g = C("g")

m.w = i
d.w = i
d.v = i
i.q = d
j.w = i
g.q = d
assert g.q.v.q.txt == "
class A:
    def __init__(self, txt: str):
        self.w: C = None
        self.txt = txt

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

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

m = A("m")
d = B("d")
i = C("i")
j = A("j")
g = C("g")

m.w = i
d.w = i
d.v = i
i.q = d
j.w = i
g.q = d
assert g.q.v.q.txt == "d"