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

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

n = A("n")
c = B("c")
d = B("d")
j = A("j")
a = A("a")
g = B("g")
l = B("l")

n.z = j
n.y = a
c.s = g
d.s = l
j.z = a
j.y = n
a.z = j
a.y = n
g.s = d
l.s = d
assert c.s.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.y: A = None
        self.txt = txt

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

n = A("n")
c = B("c")
d = B("d")
j = A("j")
a = A("a")
g = B("g")
l = B("l")

n.z = j
n.y = a
c.s = g
d.s = l
j.z = a
j.y = n
a.z = j
a.y = n
g.s = d
l.s = d
assert c.s.s.s.s.txt == "d"