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

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

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

n = A("n")
a = B("a")
g = C("g")
d = A("d")
j = B("j")
l = C("l")

n.o = d
n.r = g
a.s = g
g.o = l
g.q = l
d.o = n
d.r = g
j.s = l
l.o = g
l.q = g
assert g.o.o.q.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.r: C = None
        self.txt = txt

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

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

n = A("n")
a = B("a")
g = C("g")
d = A("d")
j = B("j")
l = C("l")

n.o = d
n.r = g
a.s = g
g.o = l
g.q = l
d.o = n
d.r = g
j.s = l
l.o = g
l.q = g
assert g.o.o.q.txt == "l"