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

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

n = A("n")
d = B("d")
k = A("k")
e = A("e")
f = A("f")
c = B("c")

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

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

n = A("n")
d = B("d")
k = A("k")
e = A("e")
f = A("f")
c = B("c")

n.y = d
d.q = e
d.p = f
k.y = d
e.y = d
f.y = d
c.q = f
c.p = e
assert e.y.p.y.txt == "d"