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

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

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

b = A("b")
e = B("e")
m = C("m")
k = A("k")
d = A("d")
j = C("j")
f = C("f")
i = C("i")

b.y = j
e.p = b
m.q = i
m.p = f
m.v = k
k.y = i
d.y = i
j.q = f
j.p = m
j.v = k
f.q = m
f.p = j
f.v = k
i.q = f
i.p = m
i.v = b
assert i.v.y.q.p.txt == "
class A:
    def __init__(self, txt: str):
        self.y: C = None
        self.txt = txt

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

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

b = A("b")
e = B("e")
m = C("m")
k = A("k")
d = A("d")
j = C("j")
f = C("f")
i = C("i")

b.y = j
e.p = b
m.q = i
m.p = f
m.v = k
k.y = i
d.y = i
j.q = f
j.p = m
j.v = k
f.q = m
f.p = j
f.v = k
i.q = f
i.p = m
i.v = b
assert i.v.y.q.p.txt == "j"