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

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

l = A("l")
h = B("h")
d = A("d")
n = B("n")
e = A("e")
c = B("c")
j = B("j")

l.y = h
h.x = n
h.y = c
d.y = n
n.x = c
n.y = h
e.y = j
c.x = n
c.y = j
j.x = c
j.y = n
assert c.y.x.x.y.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

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

l = A("l")
h = B("h")
d = A("d")
n = B("n")
e = A("e")
c = B("c")
j = B("j")

l.y = h
h.x = n
h.y = c
d.y = n
n.x = c
n.y = h
e.y = j
c.x = n
c.y = j
j.x = c
j.y = n
assert c.y.x.x.y.x.x.txt == "c"