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

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

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

c.y = i
c.z = i
f.p = c
f.q = k
i.y = c
i.z = c
d.p = i
d.q = k
k.p = c
k.q = d
assert i.z.y.y.z.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.z: A = None
        self.txt = txt

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

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

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