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

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

c = A("c")
h = B("h")
k = A("k")
b = B("b")
g = B("g")
j = A("j")
n = A("n")

c.r = g
h.y = b
h.x = k
k.r = h
b.y = h
b.x = c
g.y = h
g.x = j
j.r = g
n.r = h
assert g.y.x.r.y.y.x.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

c = A("c")
h = B("h")
k = A("k")
b = B("b")
g = B("g")
j = A("j")
n = A("n")

c.r = g
h.y = b
h.x = k
k.r = h
b.y = h
b.x = c
g.y = h
g.x = j
j.r = g
n.r = h
assert g.y.x.r.y.y.x.r.txt == "h"