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

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

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

e = A("e")
a = B("a")
d = C("d")
f = B("f")
h = A("h")

e.q = h
e.v = h
a.s = d
a.y = d
a.t = e
d.t = h
d.s = f
f.s = d
f.y = d
f.t = e
h.q = e
h.v = e
assert h.v.q.v.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.v: A = None
        self.txt = txt

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

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

e = A("e")
a = B("a")
d = C("d")
f = B("f")
h = A("h")

e.q = h
e.v = h
a.s = d
a.y = d
a.t = e
d.t = h
d.s = f
f.s = d
f.y = d
f.t = e
h.q = e
h.v = e
assert h.v.q.v.txt == "e"