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

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

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

a = A("a")
i = B("i")
m = C("m")
g = A("g")
c = C("c")
k = B("k")
j = A("j")

a.q = c
a.t = m
i.y = g
m.r = c
g.q = c
g.t = c
c.r = m
k.y = a
j.q = m
j.t = m
assert g.t.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.t: C = None
        self.txt = txt

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

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

a = A("a")
i = B("i")
m = C("m")
g = A("g")
c = C("c")
k = B("k")
j = A("j")

a.q = c
a.t = m
i.y = g
m.r = c
g.q = c
g.t = c
c.r = m
k.y = a
j.q = m
j.t = m
assert g.t.r.r.txt == "c"