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

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

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

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

g.y = d
g.q = j
b.x = g
j.t = d
j.o = g
d.y = g
d.q = j
l.x = d
assert l.x.q.o.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.q: C = None
        self.txt = txt

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

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

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

g.y = d
g.q = j
b.x = g
j.t = d
j.o = g
d.y = g
d.q = j
l.x = d
assert l.x.q.o.txt == "g"