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

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

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

g = A("g")
b = B("b")
k = C("k")
i = C("i")

g.y = b
b.y = g
b.p = i
k.q = g
i.q = g
assert g.y.p.q.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

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

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

g = A("g")
b = B("b")
k = C("k")
i = C("i")

g.y = b
b.y = g
b.p = i
k.q = g
i.q = g
assert g.y.p.q.txt == "g"