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

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

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

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

b.q = d
j.r = g
j.w = b
j.t = i
g.p = d
g.q = d
i.r = g
i.w = b
i.t = j
d.q = b
assert g.p.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.txt = txt

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

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

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

b.q = d
j.r = g
j.w = b
j.t = i
g.p = d
g.q = d
i.r = g
i.w = b
i.t = j
d.q = b
assert g.p.q.q.txt == "d"