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

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

a = A("a")
f = B("f")
c = B("c")
j = A("j")
d = B("d")
k = A("k")
n = A("n")
i = B("i")

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

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

a = A("a")
f = B("f")
c = B("c")
j = A("j")
d = B("d")
k = A("k")
n = A("n")
i = B("i")

a.y = f
f.y = d
f.p = d
c.y = d
c.p = f
j.y = f
d.y = i
d.p = f
k.y = d
n.y = d
i.y = c
i.p = d
assert c.p.y.y.y.txt == "c"