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

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

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

g = A("g")
n = B("n")
j = C("j")
l = B("l")
f = C("f")
m = A("m")

g.p = m
g.y = m
n.o = j
n.q = m
j.v = l
l.o = f
l.q = m
f.v = l
m.p = g
m.y = g
assert n.q.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.y: A = None
        self.txt = txt

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

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

g = A("g")
n = B("n")
j = C("j")
l = B("l")
f = C("f")
m = A("m")

g.p = m
g.y = m
n.o = j
n.q = m
j.v = l
l.o = f
l.q = m
f.v = l
m.p = g
m.y = g
assert n.q.y.y.txt == "m"