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

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

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

l = A("l")
g = B("g")
n = C("n")
i = C("i")
f = A("f")
e = B("e")
j = C("j")
d = B("d")

l.p = f
g.q = f
g.z = f
n.w = f
i.w = f
f.p = l
e.q = f
e.z = l
j.w = l
d.q = l
d.z = f
assert i.w.p.p.p.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.txt = txt

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

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

l = A("l")
g = B("g")
n = C("n")
i = C("i")
f = A("f")
e = B("e")
j = C("j")
d = B("d")

l.p = f
g.q = f
g.z = f
n.w = f
i.w = f
f.p = l
e.q = f
e.z = l
j.w = l
d.q = l
d.z = f
assert i.w.p.p.p.p.p.p.txt == "f"