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

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

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

b = A("b")
d = B("d")
g = C("g")
c = A("c")
i = C("i")

b.t = d
d.q = c
d.w = g
g.v = b
g.q = d
c.t = d
i.v = b
i.q = d
assert i.q.w.v.t.q.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.txt = txt

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

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

b = A("b")
d = B("d")
g = C("g")
c = A("c")
i = C("i")

b.t = d
d.q = c
d.w = g
g.v = b
g.q = d
c.t = d
i.v = b
i.q = d
assert i.q.w.v.t.q.txt == "c"