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

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

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

e = A("e")
h = B("h")
d = C("d")
n = A("n")
l = C("l")

e.y = n
e.x = n
e.o = l
h.r = d
h.s = e
h.q = l
d.p = e
n.y = e
n.x = e
n.o = d
l.p = n
assert h.r.p.y.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.o: C = None
        self.x: A = None
        self.txt = txt

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

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

e = A("e")
h = B("h")
d = C("d")
n = A("n")
l = C("l")

e.y = n
e.x = n
e.o = l
h.r = d
h.s = e
h.q = l
d.p = e
n.y = e
n.x = e
n.o = d
l.p = n
assert h.r.p.y.y.y.txt == "n"