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

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

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

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

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

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

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