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

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

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

f = A("f")
c = B("c")
k = C("k")
n = A("n")
g = B("g")

f.p = n
c.q = k
c.w = g
c.o = g
k.v = f
k.q = f
n.p = f
g.q = k
g.w = c
g.o = c
assert g.w.o.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.txt = txt

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

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

f = A("f")
c = B("c")
k = C("k")
n = A("n")
g = B("g")

f.p = n
c.q = k
c.w = g
c.o = g
k.v = f
k.q = f
n.p = f
g.q = k
g.w = c
g.o = c
assert g.w.o.q.q.txt == "f"