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

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

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

i = A("i")
m = B("m")
j = C("j")
g = C("g")
f = B("f")
e = A("e")
n = B("n")
h = B("h")

i.u = e
i.r = e
m.q = g
m.p = i
j.y = g
j.o = g
g.y = j
g.o = j
f.q = j
f.p = e
e.u = i
e.r = i
n.q = g
n.p = i
h.q = j
h.p = i
assert g.y.y.o.o.y.y.o.txt == "
class A:
    def __init__(self, txt: str):
        self.u: A = None
        self.r: A = None
        self.txt = txt

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

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

i = A("i")
m = B("m")
j = C("j")
g = C("g")
f = B("f")
e = A("e")
n = B("n")
h = B("h")

i.u = e
i.r = e
m.q = g
m.p = i
j.y = g
j.o = g
g.y = j
g.o = j
f.q = j
f.p = e
e.u = i
e.r = i
n.q = g
n.p = i
h.q = j
h.p = i
assert g.y.y.o.o.y.y.o.txt == "j"