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

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

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

h = A("h")
f = B("f")
j = C("j")
a = B("a")
c = C("c")
d = C("d")
l = C("l")
b = A("b")
i = C("i")
m = A("m")

h.y = f
h.o = f
f.o = j
j.q = m
a.o = d
c.q = h
d.q = m
l.q = b
b.y = f
b.o = a
i.q = h
m.y = a
m.o = a
assert d.q.y.o.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.o: B = None
        self.txt = txt

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

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

h = A("h")
f = B("f")
j = C("j")
a = B("a")
c = C("c")
d = C("d")
l = C("l")
b = A("b")
i = C("i")
m = A("m")

h.y = f
h.o = f
f.o = j
j.q = m
a.o = d
c.q = h
d.q = m
l.q = b
b.y = f
b.o = a
i.q = h
m.y = a
m.o = a
assert d.q.y.o.txt == "d"