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

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

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

n = A("n")
d = B("d")
f = C("f")
a = A("a")
e = B("e")
g = B("g")

n.q = a
d.v = e
f.q = n
a.q = n
e.v = d
g.v = d
assert e.v.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.txt = txt

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

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

n = A("n")
d = B("d")
f = C("f")
a = A("a")
e = B("e")
g = B("g")

n.q = a
d.v = e
f.q = n
a.q = n
e.v = d
g.v = d
assert e.v.v.v.txt == "d"