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.z: A = None
        self.txt = txt

f = A("f")
i = B("i")
h = A("h")
g = B("g")
k = A("k")
d = B("d")
c = B("c")

f.p = h
f.y = k
i.z = k
h.p = k
h.y = k
g.z = f
k.p = h
k.y = f
d.z = f
c.z = f
assert g.z.y.p.y.y.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.z: A = None
        self.txt = txt

f = A("f")
i = B("i")
h = A("h")
g = B("g")
k = A("k")
d = B("d")
c = B("c")

f.p = h
f.y = k
i.z = k
h.p = k
h.y = k
g.z = f
k.p = h
k.y = f
d.z = f
c.z = f
assert g.z.y.p.y.y.y.txt == "k"