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

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

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

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

h.u = m
h.s = m
h.q = f
m.p = e
d.p = f
e.p = f
f.u = m
f.s = m
f.q = h
assert h.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.s: B = None
        self.q: A = None
        self.txt = txt

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

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

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

h.u = m
h.s = m
h.q = f
m.p = e
d.p = f
e.p = f
f.u = m
f.s = m
f.q = h
assert h.q.q.q.q.txt == "h"