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

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

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

k = A("k")
d = B("d")
l = C("l")
f = A("f")
j = C("j")
a = C("a")
h = B("h")

k.p = f
k.y = f
d.w = k
l.o = k
l.s = j
f.p = k
f.y = k
j.o = k
j.s = a
a.o = k
a.s = l
h.w = f
assert j.s.o.y.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.y: A = None
        self.txt = txt

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

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

k = A("k")
d = B("d")
l = C("l")
f = A("f")
j = C("j")
a = C("a")
h = B("h")

k.p = f
k.y = f
d.w = k
l.o = k
l.s = j
f.p = k
f.y = k
j.o = k
j.s = a
a.o = k
a.s = l
h.w = f
assert j.s.o.y.txt == "f"